-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1288 from Khaybee/fix/user-creation
fix: Ensure user creation runs in a transaction
- Loading branch information
Showing
11 changed files
with
166 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { OrganisationInterface } from '../interfaces/OrganisationInterface'; | ||
|
||
import { CreateRecordGeneric } from '@shared/helpers/createRecordGeneric'; | ||
type CreateOrganisationType = Partial<OrganisationInterface>; | ||
|
||
export type CreateOrganisationRecordOptions = CreateRecordGeneric<CreateOrganisationType>; | ||
export default CreateOrganisationType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ export interface OrganisationInterface { | |
address: string; | ||
|
||
state: string; | ||
|
||
userId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,12 @@ import { User } from '../../user/entities/user.entity'; | |
import { Organisation } from '../entities/organisations.entity'; | ||
import { getRepositoryToken } from '@nestjs/typeorm'; | ||
import UserService from '../../user/user.service'; | ||
import { | ||
ForbiddenException, | ||
NotFoundException, | ||
} from '@nestjs/common'; | ||
import { ForbiddenException, NotFoundException } from '@nestjs/common'; | ||
import { Profile } from '../../profile/entities/profile.entity'; | ||
import { OrganisationUserRole } from '../../../modules/role/entities/organisation-user-role.entity'; | ||
import { Role } from '../../../modules/role/entities/role.entity'; | ||
import { CustomHttpException } from '@shared/helpers/custom-http-filter'; | ||
|
||
import { CreateOrganisationRecordOptions } from '../dto/create-organisation-options'; | ||
describe('OrganisationsService', () => { | ||
let service: OrganisationsService; | ||
let userRepository: Repository<User>; | ||
|
@@ -90,8 +87,14 @@ describe('OrganisationsService', () => { | |
}); | ||
describe('create', () => { | ||
it('should create a new organisation', async () => { | ||
const createOrganisationDto = { name: 'Test Org', email: '[email protected]' }; | ||
const userId = 'user-id'; | ||
const createOrganisationDto = { name: 'Test Org', email: '[email protected]' }; | ||
const createOrganisationPayload: CreateOrganisationRecordOptions = { | ||
createPayload: { ...createOrganisationDto, userId }, | ||
dbTransaction: { | ||
useTransaction: false, | ||
}, | ||
}; | ||
const user = { id: userId }; | ||
const superAdminRole = { id: 'role-id', name: 'super_admin', description: '', permissions: [] }; | ||
const newOrganisation = { ...createOrganisationDto, id: 'org-id', owner: user }; | ||
|
@@ -108,7 +111,7 @@ describe('OrganisationsService', () => { | |
jest.spyOn(organisationRepository, 'save').mockResolvedValue(newOrganisation as Organisation); | ||
jest.spyOn(organisationUserRole, 'save').mockResolvedValue(adminReponse); | ||
|
||
const result = await service.create(createOrganisationDto, userId); | ||
const result = await service.create(createOrganisationPayload); | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
|
Oops, something went wrong.