Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@swc/helpers": "^0.5.17",
"@types/bcrypt": "^6.0.0",
"@types/express": "^5.0.3",
"@types/jest": "^29.5.14",
"@types/jest": "^30.0.0",
"@types/luxon": "^3.6.2",
"@types/node": "22.16.4",
"@types/nodemailer": "^6.4.17",
Expand All @@ -103,7 +103,7 @@
"@ufb/prettier-config": "workspace:*",
"@ufb/tsconfig": "workspace:*",
"eslint": "catalog:",
"jest": "^29.7.0",
"jest": "^30.0.5",
"mockdate": "^3.0.5",
"prettier": "catalog:",
"supertest": "^7.1.4",
Expand Down
42 changes: 21 additions & 21 deletions apps/api/src/common/repositories/opensearch.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ describe('Opensearch Repository Test suite', () => {

await osRepo.createIndex({ index });

expect(osClient.indices.create).toBeCalledTimes(1);
expect(osClient.indices.create).toBeCalledWith({
expect(osClient.indices.create).toHaveBeenCalledTimes(1);
expect(osClient.indices.create).toHaveBeenCalledWith({
index: indexName,
body: {
settings: {
Expand All @@ -105,8 +105,8 @@ describe('Opensearch Repository Test suite', () => {
},
},
});
expect(osClient.indices.putAlias).toBeCalledTimes(1);
expect(osClient.indices.putAlias).toBeCalledWith({
expect(osClient.indices.putAlias).toHaveBeenCalledTimes(1);
expect(osClient.indices.putAlias).toHaveBeenCalledWith({
index: indexName,
name: index,
});
Expand All @@ -125,9 +125,9 @@ describe('Opensearch Repository Test suite', () => {

await osRepo.putMappings(dto);

expect(osClient.indices.exists).toBeCalledTimes(1);
expect(osClient.indices.putMapping).toBeCalledTimes(1);
expect(osClient.indices.putMapping).toBeCalledWith({
expect(osClient.indices.exists).toHaveBeenCalledTimes(1);
expect(osClient.indices.putMapping).toHaveBeenCalledTimes(1);
expect(osClient.indices.putMapping).toHaveBeenCalledWith({
index: dto.index,
body: { properties: dto.mappings },
});
Expand All @@ -141,12 +141,12 @@ describe('Opensearch Repository Test suite', () => {
.mockResolvedValue({ statusCode: 404 } as never);
jest.spyOn(osClient.indices, 'putMapping');

await expect(osRepo.putMappings(dto)).rejects.toThrowError(
await expect(osRepo.putMappings(dto)).rejects.toThrow(
new NotFoundException('index is not found'),
);

expect(osClient.indices.exists).toBeCalledTimes(1);
expect(osClient.indices.putMapping).not.toBeCalled();
expect(osClient.indices.exists).toHaveBeenCalledTimes(1);
expect(osClient.indices.putMapping).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -179,9 +179,9 @@ describe('Opensearch Repository Test suite', () => {
const response = await osRepo.createData(dto);

expect(response.id).toEqual(dto.id);
expect(osClient.indices.getMapping).toBeCalledTimes(1);
expect(osClient.index).toBeCalledTimes(1);
expect(osClient.index).toBeCalledWith({
expect(osClient.indices.getMapping).toHaveBeenCalledTimes(1);
expect(osClient.index).toHaveBeenCalledTimes(1);
expect(osClient.index).toHaveBeenCalledWith({
id: dto.id,
index: 'channel_' + index,
body: dto.data,
Expand Down Expand Up @@ -213,13 +213,13 @@ describe('Opensearch Repository Test suite', () => {
},
} as never);

await expect(osRepo.createData(dto)).rejects.toThrowError(
await expect(osRepo.createData(dto)).rejects.toThrow(
new NotFoundException('index is not found'),
);

expect(osClient.indices.exists).toBeCalledTimes(1);
expect(osClient.indices.getMapping).not.toBeCalled();
expect(osClient.index).not.toBeCalled();
expect(osClient.indices.exists).toHaveBeenCalledTimes(1);
expect(osClient.indices.getMapping).not.toHaveBeenCalled();
expect(osClient.index).not.toHaveBeenCalled();
});
it('creating data fails with invalid data', async () => {
const index = faker.number.int().toString();
Expand Down Expand Up @@ -250,13 +250,13 @@ describe('Opensearch Repository Test suite', () => {
},
} as never);

await expect(osRepo.createData(dto)).rejects.toThrowError(
await expect(osRepo.createData(dto)).rejects.toThrow(
new InternalServerErrorException('error!!!'),
);

expect(osClient.indices.exists).toBeCalledTimes(1);
expect(osClient.indices.getMapping).toBeCalledTimes(1);
expect(osClient.index).not.toBeCalled();
expect(osClient.indices.exists).toHaveBeenCalledTimes(1);
expect(osClient.indices.getMapping).toHaveBeenCalledTimes(1);
expect(osClient.index).not.toHaveBeenCalled();
});
});

Expand Down
24 changes: 12 additions & 12 deletions apps/api/src/domains/admin/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ describe('auth service ', () => {
const timeoutTime = await authService.sendEmailCode(dto);

expect(new Date(timeoutTime) > new Date()).toEqual(true);
expect(MockEmailVerificationMailingService.send).toBeCalledTimes(1);
expect(MockEmailVerificationMailingService.send).toHaveBeenCalledTimes(1);
});
it('sending a code by email succeeds with a duplicate email', async () => {
const duplicateEmail = emailFixture;
dto.email = duplicateEmail;
jest.spyOn(MockEmailVerificationMailingService, 'send');

await expect(authService.sendEmailCode(dto)).rejects.toThrowError(
await expect(authService.sendEmailCode(dto)).rejects.toThrow(
UserAlreadyExistsException,
);

expect(MockEmailVerificationMailingService.send).not.toBeCalled();
expect(MockEmailVerificationMailingService.send).not.toHaveBeenCalled();
});
});

Expand All @@ -126,7 +126,7 @@ describe('auth service ', () => {
dto.email = faker.internet.email();
dto.password = passwordFixture;

await expect(authService.validateEmailUser(dto)).rejects.toThrowError(
await expect(authService.validateEmailUser(dto)).rejects.toThrow(
UserNotFoundException,
);
});
Expand All @@ -136,7 +136,7 @@ describe('auth service ', () => {
dto.email = faker.internet.email();
dto.password = invalidPassword;

await expect(authService.validateEmailUser(dto)).rejects.toThrowError(
await expect(authService.validateEmailUser(dto)).rejects.toThrow(
PasswordNotMatchException,
);
});
Expand All @@ -162,11 +162,11 @@ describe('auth service ', () => {
jest.spyOn(userRepo, 'findOneBy').mockResolvedValue(null);
jest.spyOn(userRepo, 'save');

await expect(authService.signUpEmailUser(dto)).rejects.toThrowError(
await expect(authService.signUpEmailUser(dto)).rejects.toThrow(
NotVerifiedEmailException,
);

expect(userRepo.save).not.toBeCalled();
expect(userRepo.save).not.toHaveBeenCalled();
});
it('signing up by an email fails with a not verification requested email', async () => {
const dto = new SignUpEmailUserDto();
Expand All @@ -176,11 +176,11 @@ describe('auth service ', () => {
jest.spyOn(userRepo, 'findOneBy').mockResolvedValue(null);
jest.spyOn(userRepo, 'save');

await expect(authService.signUpEmailUser(dto)).rejects.toThrowError(
await expect(authService.signUpEmailUser(dto)).rejects.toThrow(
new BadRequestException('must request email verification'),
);

expect(userRepo.save).not.toBeCalled();
expect(userRepo.save).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -218,7 +218,7 @@ describe('auth service ', () => {
UserBlockedException,
);

expect(MockJwtService.sign).not.toBeCalled();
expect(MockJwtService.sign).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -266,14 +266,14 @@ describe('auth service ', () => {
it('getting an oauth login url fails with no oauth using tenant', async () => {
tenantRepo.setUseOAuth(false, null);

await expect(authService.getOAuthLoginURL()).rejects.toThrowError(
await expect(authService.getOAuthLoginURL()).rejects.toThrow(
new BadRequestException('OAuth login is disabled.'),
);
});
it('getting an oauth login url fails with no oauthconfig tenant', async () => {
tenantRepo.setUseOAuth(true, null);

await expect(authService.getOAuthLoginURL()).rejects.toThrowError(
await expect(authService.getOAuthLoginURL()).rejects.toThrow(
new BadRequestException('OAuth Config is required.'),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('ChannelController', () => {
dto.fields = [];

await channelController.create(projectId, dto);
expect(MockChannelService.create).toBeCalledTimes(1);
expect(MockChannelService.create).toHaveBeenCalledTimes(1);
});
});
describe('findAllByProjectId', () => {
Expand All @@ -71,7 +71,7 @@ describe('ChannelController', () => {
dto.page = faker.number.int();

await channelController.findAllByProjectId(projectId, dto);
expect(MockChannelService.findAllByProjectId).toBeCalledTimes(1);
expect(MockChannelService.findAllByProjectId).toHaveBeenCalledTimes(1);
});
});
describe('delete', () => {
Expand All @@ -80,7 +80,7 @@ describe('ChannelController', () => {
const channelId = faker.number.int();

await channelController.delete(channelId);
expect(MockChannelService.deleteById).toBeCalledTimes(1);
expect(MockChannelService.deleteById).toHaveBeenCalledTimes(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('FieldService suite', () => {

expect(fields.length).toBe(fieldCount + 4);

expect(optionRepo.save).toBeCalledTimes(selectFieldCount);
expect(optionRepo.save).toHaveBeenCalledTimes(selectFieldCount);
});
it('creating many fields fails with duplicate names', async () => {
const channelId = faker.number.int();
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('FieldService suite', () => {

await fieldService.replaceMany(dto);

expect(fieldRepo.save).toBeCalledTimes(
expect(fieldRepo.save).toHaveBeenCalledTimes(
updatingFieldDtos.length + creatingFieldDtos.length,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ describe('SelectOptionController', () => {
.mockReturnValue(options);
const fieldId = faker.number.int();
await optionController.getOptions(fieldId);
expect(MockSelectOptionService.findByFieldId).toBeCalledTimes(1);
expect(MockSelectOptionService.findByFieldId).toHaveBeenCalledTimes(1);
});
it('creaetOption', async () => {
const fieldId = faker.number.int();
const dto = new CreateOptionRequestDto();
dto.name = faker.string.sample();
await optionController.createOption(fieldId, dto);
expect(MockSelectOptionService.create).toBeCalledTimes(1);
expect(MockSelectOptionService.create).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('Option Test suite', () => {

await optionService.replaceMany(dto);

expect(optionRepo.save).toBeCalledTimes(length);
expect(optionRepo.save).toHaveBeenCalledTimes(length);
});
});
});
10 changes: 5 additions & 5 deletions apps/api/src/domains/admin/feedback/feedback.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('FeedbackController', () => {
} as ChannelEntity);

await feedbackController.create(projectId, channelId, {});
expect(MockFeedbackService.create).toBeCalledTimes(1);
expect(MockFeedbackService.create).toHaveBeenCalledTimes(1);
});
it('findByChannelId', async () => {
const channelId = faker.number.int();
Expand All @@ -92,7 +92,7 @@ describe('FeedbackController', () => {
);

await feedbackController.findByChannelId(channelId, dto);
expect(MockFeedbackService.findByChannelIdV2).toBeCalledTimes(1);
expect(MockFeedbackService.findByChannelIdV2).toHaveBeenCalledTimes(1);
});
it('exportFeedbacks', async () => {
const projectId = faker.number.int();
Expand Down Expand Up @@ -123,15 +123,15 @@ describe('FeedbackController', () => {
userDto,
);

expect(MockFeedbackService.generateFile).toBeCalledTimes(1);
expect(MockFeedbackService.generateFile).toHaveBeenCalledTimes(1);
});
it('updateFeedback', async () => {
const channelId = faker.number.int();
const feedbackId = faker.number.int();
const body = { [faker.string.sample()]: faker.string.sample() };

await feedbackController.updateFeedback(channelId, feedbackId, body);
expect(MockFeedbackService.updateFeedback).toBeCalledTimes(1);
expect(MockFeedbackService.updateFeedback).toHaveBeenCalledTimes(1);
});

it('delete Feedback', async () => {
Expand All @@ -142,6 +142,6 @@ describe('FeedbackController', () => {
dto.feedbackIds = feedbackIds;

await feedbackController.deleteMany(channelId, dto);
expect(MockFeedbackService.deleteByIds).toBeCalledTimes(1);
expect(MockFeedbackService.deleteByIds).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('ApiKeyController', () => {

await apiKeyController.create(projectId, {});

expect(MockApiKeyService.create).toBeCalledTimes(1);
expect(MockApiKeyService.create).toHaveBeenCalledTimes(1);
});
it('creating succeeds with an api key', async () => {
jest.spyOn(MockApiKeyService, 'create');
Expand All @@ -61,7 +61,7 @@ describe('ApiKeyController', () => {

await apiKeyController.create(projectId, { value });

expect(MockApiKeyService.create).toBeCalledTimes(1);
expect(MockApiKeyService.create).toHaveBeenCalledTimes(1);
});
});
describe('findAll', () => {
Expand All @@ -71,7 +71,7 @@ describe('ApiKeyController', () => {

await apiKeyController.findAll(projectId);

expect(MockApiKeyService.findAllByProjectId).toBeCalledTimes(1);
expect(MockApiKeyService.findAllByProjectId).toHaveBeenCalledTimes(1);
});
});
describe('softDelete', () => {
Expand All @@ -81,7 +81,7 @@ describe('ApiKeyController', () => {

await apiKeyController.softDelete(apiKeyId);

expect(MockApiKeyService.softDeleteById).toBeCalledTimes(1);
expect(MockApiKeyService.softDeleteById).toHaveBeenCalledTimes(1);
});
});
describe('recover', () => {
Expand All @@ -91,7 +91,7 @@ describe('ApiKeyController', () => {

await apiKeyController.recover(apiKeyId);

expect(MockApiKeyService.recoverById).toBeCalledTimes(1);
expect(MockApiKeyService.recoverById).toHaveBeenCalledTimes(1);
});
});
describe('delete', () => {
Expand All @@ -101,7 +101,7 @@ describe('ApiKeyController', () => {

await apiKeyController.delete(apiKeyId);

expect(MockApiKeyService.deleteById).toBeCalledTimes(1);
expect(MockApiKeyService.deleteById).toHaveBeenCalledTimes(1);
});
});
});
Loading