Skip to content

Commit

Permalink
add registration-pin entity
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechGrancow committed Nov 22, 2023
1 parent bbd7075 commit 4f74e80
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
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);
});
});
});
});
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;
}
}

0 comments on commit 4f74e80

Please sign in to comment.