Skip to content

Commit 363b644

Browse files
committed
fix tests
1 parent 9e7bfb5 commit 363b644

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

apps/server/src/modules/user/repo/scope/user.scope.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ describe('UserScope', () => {
325325
it('should add a query that removes deleted users', () => {
326326
scope1.withDeleted(false);
327327

328-
expect(scope1.query).toEqual({ $or: [{ deletedAt: { $exists: false } }, { deletedAt: null }] });
328+
expect(scope1.query).toEqual({
329+
$or: [{ deletedAt: { $exists: false } }, { deletedAt: null }, { deletedAt: { $gte: expect.any(Date) } }],
330+
});
329331
});
330332
});
331333
});

apps/server/src/modules/user/repo/scope/user.scope.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export class UserScope extends Scope<User> {
9595

9696
public withDeleted(deleted?: boolean): UserScope {
9797
if (!deleted) {
98-
this.addQuery({ $or: [{ deletedAt: { $exists: false } }, { deletedAt: null }] });
98+
this.addQuery({
99+
$or: [{ deletedAt: { $exists: false } }, { deletedAt: null }, { deletedAt: { $gte: new Date() } }],
100+
});
99101
}
100102

101103
return this;

apps/server/src/modules/user/repo/user-do.repo.integration.spec.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,19 @@ describe('UserRepo', () => {
608608
});
609609

610610
const setupFind = async () => {
611-
const query = {
611+
let query = {
612612
schoolId: undefined,
613613
isOutdated: undefined,
614614
lastLoginSystemChangeSmallerThan: undefined,
615615
outdatedSince: undefined,
616616
lastLoginSystemChangeBetweenEnd: undefined,
617617
lastLoginSystemChangeBetweenStart: undefined,
618618
};
619+
const deletedFilter = {
620+
$or: [{ deletedAt: { $exists: false } }, { deletedAt: null }, { deletedAt: { $gte: expect.any(Date) } }],
621+
};
622+
623+
query = { ...query, ...deletedFilter };
619624

620625
const options: IFindOptions<UserDo> = {};
621626

@@ -630,12 +635,12 @@ describe('UserRepo', () => {
630635

631636
const emFindAndCountSpy = jest.spyOn(em, 'findAndCount');
632637

633-
return { query, options, users, emFindAndCountSpy };
638+
return { query, options, users, emFindAndCountSpy, deletedFilter };
634639
};
635640

636641
describe('sorting', () => {
637642
it('should create queryOrderMap with options.order', async () => {
638-
const { query, options, emFindAndCountSpy } = await setupFind();
643+
const { query, options, emFindAndCountSpy, deletedFilter } = await setupFind();
639644
options.order = {
640645
id: SortOrder.asc,
641646
};
@@ -644,22 +649,22 @@ describe('UserRepo', () => {
644649

645650
expect(emFindAndCountSpy).toHaveBeenCalledWith(
646651
User,
647-
{},
652+
deletedFilter,
648653
expect.objectContaining<FindOptions<User>>({
649654
orderBy: expect.objectContaining<QueryOrderMap<User>>({ _id: options.order.id }) as QueryOrderMap<User>,
650655
})
651656
);
652657
});
653658

654659
it('should create queryOrderMap with an empty object', async () => {
655-
const { query, options, emFindAndCountSpy } = await setupFind();
660+
const { query, options, emFindAndCountSpy, deletedFilter } = await setupFind();
656661
options.order = undefined;
657662

658663
await repo.find(query, options);
659664

660665
expect(emFindAndCountSpy).toHaveBeenCalledWith(
661666
User,
662-
{},
667+
deletedFilter,
663668
expect.objectContaining<FindOptions<User>>({
664669
orderBy: expect.objectContaining<QueryOrderMap<User>>({}) as QueryOrderMap<User>,
665670
})
@@ -740,6 +745,9 @@ describe('UserRepo', () => {
740745
lastLoginSystemChangeBetweenStart: new Date(),
741746
lastLoginSystemChangeBetweenEnd: new Date(),
742747
};
748+
const deletedFilter = {
749+
$or: [{ deletedAt: { $exists: false } }, { deletedAt: null }, { deletedAt: { $gte: expect.any(Date) } }],
750+
};
743751

744752
const options: IFindOptions<UserDo> = {};
745753

@@ -799,6 +807,13 @@ describe('UserRepo', () => {
799807
$eq: query.outdatedSince,
800808
},
801809
},
810+
{
811+
$or: [
812+
{ deletedAt: { $exists: false } },
813+
{ deletedAt: null },
814+
{ deletedAt: { $gte: expect.any(Date) } },
815+
],
816+
},
802817
],
803818
},
804819
expect.objectContaining<FindOptions<User>>({

0 commit comments

Comments
 (0)