Merge pull request #510 from Hexastack/fix/label-strict-null-check

fix: label
This commit is contained in:
Med Marrouchi 2025-01-03 16:12:36 +01:00 committed by GitHub
commit 0448cc5bc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -82,10 +82,10 @@ describe('LabelController', () => {
labelService = module.get<LabelService>(LabelService);
subscriberService = module.get<SubscriberService>(SubscriberService);
labelController = module.get<LabelController>(LabelController);
label = await labelService.findOne({ name: 'TEST_TITLE_1' });
labelToDelete = await labelService.findOne({
label = (await labelService.findOne({ name: 'TEST_TITLE_1' })) as Label;
labelToDelete = (await labelService.findOne({
name: 'TEST_TITLE_2',
});
})) as Label;
});
afterEach(jest.clearAllMocks);

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -21,7 +21,7 @@ import {
rootMongooseTestModule,
} from '@/utils/test/test';
import { Label, LabelModel } from '../schemas/label.schema';
import { Label, LabelFull, LabelModel } from '../schemas/label.schema';
import { Subscriber, SubscriberModel } from '../schemas/subscriber.schema';
import { LabelRepository } from './label.repository';
@ -59,8 +59,12 @@ describe('LabelRepository', () => {
describe('findOneAndPopulate', () => {
it('should find one label by id, and populate its users', async () => {
jest.spyOn(labelModel, 'findById');
const label = await labelRepository.findOne({ name: 'TEST_TITLE_2' });
const result = await labelRepository.findOneAndPopulate(label.id);
const label = (await labelRepository.findOne({
name: 'TEST_TITLE_2',
})) as Label;
const result = (await labelRepository.findOneAndPopulate(
label.id,
)) as LabelFull;
expect(labelModel.findById).toHaveBeenCalledWith(label.id, undefined);
expect(result).toEqualPayload({

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -26,8 +26,8 @@ import {
} from '@/utils/test/test';
import { LabelRepository } from '../repositories/label.repository';
import { LabelModel, Label, LabelFull } from '../schemas/label.schema';
import { SubscriberModel, Subscriber } from '../schemas/subscriber.schema';
import { Label, LabelFull, LabelModel } from '../schemas/label.schema';
import { Subscriber, SubscriberModel } from '../schemas/subscriber.schema';
import { SubscriberRepository } from './../repositories/subscriber.repository';
import { LabelService } from './label.service';
@ -101,7 +101,9 @@ describe('LabelService', () => {
describe('findOneAndPopulate', () => {
it('should find one label by id, and populate its corresponding users', async () => {
jest.spyOn(labelRepository, 'findOneAndPopulate');
const label = await labelRepository.findOne({ name: 'TEST_TITLE_1' });
const label = (await labelRepository.findOne({
name: 'TEST_TITLE_1',
})) as Label;
const result = await labelService.findOneAndPopulate(label.id);
expect(result).toEqualPayload({