mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: label unit tests
This commit is contained in:
parent
80d94699bf
commit
49f0a9e1cf
@ -49,6 +49,7 @@ describe('LabelController', () => {
|
||||
let labelService: LabelService;
|
||||
let label: Label;
|
||||
let labelToDelete: Label;
|
||||
let secondLabelToDelete: Label;
|
||||
let subscriberService: SubscriberService;
|
||||
|
||||
beforeAll(async () => {
|
||||
@ -88,6 +89,9 @@ describe('LabelController', () => {
|
||||
labelToDelete = (await labelService.findOne({
|
||||
name: 'TEST_TITLE_2',
|
||||
})) as Label;
|
||||
secondLabelToDelete = (await labelService.findOne({
|
||||
name: 'TEST_TITLE_3',
|
||||
})) as Label;
|
||||
});
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
@ -204,34 +208,6 @@ describe('LabelController', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteMany', () => {
|
||||
it('should delete multiple labels', async () => {
|
||||
const valuesToDelete = [label.id, labelToDelete.id];
|
||||
|
||||
const result = await labelController.deleteMany(valuesToDelete);
|
||||
|
||||
expect(result.deletedCount).toEqual(valuesToDelete.length);
|
||||
const remainingValues = await labelService.find({
|
||||
_id: { $in: valuesToDelete },
|
||||
});
|
||||
expect(remainingValues.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should throw BadRequestException when no IDs are provided', async () => {
|
||||
await expect(labelController.deleteMany([])).rejects.toThrow(
|
||||
BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw NotFoundException when provided IDs do not exist', async () => {
|
||||
const nonExistentIds = [NOT_FOUND_ID, NOT_FOUND_ID.replace(/9/g, '8')];
|
||||
|
||||
await expect(labelController.deleteMany(nonExistentIds)).rejects.toThrow(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateOne', () => {
|
||||
const labelUpdateDto: LabelUpdateDto = {
|
||||
description: 'test description 1',
|
||||
@ -259,4 +235,32 @@ describe('LabelController', () => {
|
||||
).rejects.toThrow(getUpdateOneError(Label.name, labelToDelete.id));
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteMany', () => {
|
||||
it('should delete multiple labels', async () => {
|
||||
const valuesToDelete = [label.id, secondLabelToDelete.id];
|
||||
|
||||
const result = await labelController.deleteMany(valuesToDelete);
|
||||
|
||||
expect(result.deletedCount).toEqual(valuesToDelete.length);
|
||||
const remainingValues = await labelService.find({
|
||||
_id: { $in: valuesToDelete },
|
||||
});
|
||||
expect(remainingValues.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should throw BadRequestException when no IDs are provided', async () => {
|
||||
await expect(labelController.deleteMany([])).rejects.toThrow(
|
||||
BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw NotFoundException when provided IDs do not exist', async () => {
|
||||
const nonExistentIds = [NOT_FOUND_ID, NOT_FOUND_ID.replace(/9/g, '8')];
|
||||
|
||||
await expect(labelController.deleteMany(nonExistentIds)).rejects.toThrow(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
11
api/src/utils/test/fixtures/label.ts
vendored
11
api/src/utils/test/fixtures/label.ts
vendored
@ -43,6 +43,17 @@ export const labels: TLabelFixtures['values'][] = [
|
||||
name: 'TEST_TITLE_2',
|
||||
title: 'test title 2',
|
||||
},
|
||||
{
|
||||
description: 'test description 3',
|
||||
label_id: {
|
||||
messenger: 'messenger',
|
||||
web: 'web',
|
||||
twitter: 'twitter',
|
||||
dimelo: 'dimelo',
|
||||
},
|
||||
name: 'TEST_TITLE_3',
|
||||
title: 'test title 3',
|
||||
},
|
||||
];
|
||||
|
||||
export const labelFixtures = getFixturesWithDefaultValues<
|
||||
|
Loading…
Reference in New Issue
Block a user