-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd7075
commit 4f74e80
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
apps/server/src/modules/registration-pin/entity/registration-pin.entity.spec.ts
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { setupEntities } from '@shared/testing'; | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { RegistrationPinsEntity } from './registration-pin.entity'; | ||
|
||
describe(RegistrationPinsEntity.name, () => { | ||
beforeAll(async () => { | ||
await setupEntities(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const setup = () => { | ||
const props = { | ||
id: new ObjectId().toHexString(), | ||
email: '[email protected]', | ||
pin: 'test123', | ||
verified: false, | ||
importHash: '02a00804nnQbLbCDEMVuk56pzZ3A0SC2cYnmM9cyY25IVOnf0K3YCKqW6zxC', | ||
}; | ||
|
||
return { props }; | ||
}; | ||
|
||
describe('constructor', () => { | ||
describe('When constructor is called', () => { | ||
it('should throw an error by empty constructor', () => { | ||
// @ts-expect-error: Test case | ||
const test = () => new RegistrationPinsEntity(); | ||
expect(test).toThrow(); | ||
}); | ||
|
||
it('should create a registrationPins by passing required properties', () => { | ||
const { props } = setup(); | ||
const entity: RegistrationPinsEntity = new RegistrationPinsEntity(props); | ||
|
||
expect(entity instanceof RegistrationPinsEntity).toEqual(true); | ||
}); | ||
|
||
it(`should return a valid object with fields values set from the provided complete props object`, () => { | ||
const { props } = setup(); | ||
const entity: RegistrationPinsEntity = new RegistrationPinsEntity(props); | ||
|
||
const entityProps = { | ||
id: entity.id, | ||
email: entity.email, | ||
pin: entity.pin, | ||
verified: entity.verified, | ||
importHash: entity.importHash, | ||
}; | ||
|
||
expect(entityProps).toEqual(props); | ||
}); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
apps/server/src/modules/registration-pin/entity/registration-pin.entity.ts
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Entity, Property } from '@mikro-orm/core'; | ||
import { EntityId } from '@shared/domain'; | ||
import { BaseEntityWithTimestamps } from '@shared/domain/entity/base.entity'; | ||
|
||
export interface RegistrationPinsProps { | ||
id?: EntityId; | ||
email: string; | ||
pin: string; | ||
verified: boolean; | ||
importHash: string; | ||
} | ||
|
||
@Entity({ tableName: 'registrationpins' }) | ||
export class RegistrationPinsEntity extends BaseEntityWithTimestamps { | ||
@Property() | ||
email: string; | ||
|
||
@Property() | ||
pin: string; | ||
|
||
@Property({ default: false }) | ||
verified: boolean; | ||
|
||
@Property() | ||
importHash: string; | ||
|
||
constructor(props: RegistrationPinsProps) { | ||
super(); | ||
if (props.id != null) { | ||
this.id = props.id; | ||
} | ||
this.email = props.email; | ||
this.pin = props.pin; | ||
this.verified = props.verified; | ||
this.importHash = props.importHash; | ||
} | ||
} |