Skip to content

Commit

Permalink
N21-2134 allow null value "deletedAt" to be shown, allow "ß" to be us…
Browse files Browse the repository at this point in the history
…ed for filtering
  • Loading branch information
GordonNicholasCap committed Aug 12, 2024
1 parent 22f993c commit 121ca55
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/shared/repo/mongo.patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export class MongoPatterns {
* Used to remove all non-language characters except numbers, whitespace or minus.
*/
static REGEX_MONGO_LANGUAGE_PATTERN_WHITELIST =
/[^\-_\w\d áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]/gi;
/[^\-_\w\d áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒß]/gi;
}
25 changes: 25 additions & 0 deletions apps/server/src/shared/repo/user/user.repo.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,31 @@ describe('user repo', () => {
// id do not exist
await expect(repo.findForImportUser(school)).rejects.toThrowError();
});

describe('when the first or lastname of the user contains "ß"', () => {
describe('when the name filter query is exactly the first or lastname of the user', () => {
const setup = async () => {
const school = schoolEntityFactory.build();
const user = userFactory.build({ school, firstName: 'Martin', lastName: 'Beißner' });
await em.persistAndFlush([user]);
em.clear();

return {
school,
user,
};
};

it('should return the searched user', async () => {
const { school, user } = await setup();

const [result, count] = await repo.findForImportUser(school, { name: user.lastName });

expect(count).toEqual(1);
expect(result.map((u) => u.id)).toContain(user.id);
});
});
});
});

describe('findByEmail', () => {
Expand Down
22 changes: 21 additions & 1 deletion apps/server/src/shared/repo/user/user.scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ describe('UserScope', () => {
expect(scope.query).toEqual({});
});
});

describe('when a name contains "ß"', () => {
const setup = () => {
const name = 'Beißner';

return {
name,
};
};

it('should return scope with added query where first or lastname is given without removing the "ß"', () => {
const { name } = setup();

scope.byName(name);

expect(scope.query).toEqual({
$or: [{ firstName: new RegExp(name, 'i') }, { lastName: new RegExp(name, 'i') }],
});
});
});
});

describe('withDeleted', () => {
Expand All @@ -173,7 +193,7 @@ describe('UserScope', () => {
it('should add a query that removes deleted users', () => {
scope.withDeleted(false);

expect(scope.query).toEqual({ deletedAt: { $exists: false } });
expect(scope.query).toEqual({ $or: [{ deletedAt: { $exists: false } }, { deletedAt: null }] });
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/shared/repo/user/user.scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UserScope extends Scope<User> {

withDeleted(deleted?: boolean): UserScope {
if (!deleted) {
this.addQuery({ deletedAt: { $exists: false } });
this.addQuery({ $or: [{ deletedAt: { $exists: false } }, { deletedAt: null }] });
}
return this;
}
Expand Down

0 comments on commit 121ca55

Please sign in to comment.