Skip to content

Commit

Permalink
test(cats): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemajesty committed Dec 1, 2023
1 parent 1a29d74 commit 6e62e68
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TZ='America/Sao_Paulo'

LOGER_LEVEL=trace

# MONGOS
MONGO_URL=mongodb://localhost:27017
MONGO_DATABASE=nestjs-microservice

Expand Down
2 changes: 1 addition & 1 deletion src/core/cats/entity/cats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CatsEntity extends BaseEntity<CatsEntity>(CatsEntitySchema) {

age: number;

constructor(readonly entity: Cat) {
constructor(entity: Cat) {
super();
Object.assign(this, this.validate(entity));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/user/entity/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class UserEntity extends BaseEntity<UserEntity>(UserEntitySchema) {

roles: UserRole[];

constructor(readonly entity: User) {
constructor(entity: User) {
super();
Object.assign(this, this.validate(entity));
}
Expand Down
12 changes: 0 additions & 12 deletions src/core/user/use-cases/__tests__/user-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,9 @@ describe('UserCreateUsecase', () => {
test('when the user is created successfully, should expect an user that has been created', async () => {
repository.findOne = jest.fn().mockResolvedValue(null);
repository.create = jest.fn().mockResolvedValue(userMock);
repository.startSession = jest.fn().mockResolvedValue({
commitTransaction: jest.fn()
});

await expect(usecase.execute(userMock, RequestMock.trancingMock)).resolves.toEqual(userMock);
});

test('when transaction throw an error, should expect an error', async () => {
repository.findOne = jest.fn().mockResolvedValue(null);
repository.create = jest.fn().mockResolvedValue(userMock);
repository.startSession = jest.fn().mockRejectedValue(new Error('startSessionError'));

await expect(usecase.execute(userMock, RequestMock.trancingMock)).rejects.toThrowError('startSessionError');
});

test('when user already exists, should expect an error', async () => {
repository.findOne = jest.fn().mockResolvedValue(userMock);
await expect(usecase.execute(userMock, RequestMock.trancingMock)).rejects.toThrowError(ApiConflictException);
Expand Down

0 comments on commit 6e62e68

Please sign in to comment.