Skip to content

Commit

Permalink
Merge pull request #151 from RJ-SMTR/feature/#94-tests-phase-1
Browse files Browse the repository at this point in the history
Chore: Use UPPER() ao invés de LOWER() no SQL
  • Loading branch information
williamfl2007 committed Dec 15, 2023
2 parents 9d0eff9 + dcbae4b commit 70039e9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
4 changes: 1 addition & 3 deletions env-example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,4 @@ TWITTER_CONSUMER_SECRET=
WORKER_HOST=redis://redis:6379/1

TEST_ADMIN_EMAIL=
TEST_ADMIN_PASSWORD=
TEST_LICENSEE_PERMIT_CODE=
TEST_LICENSEE_PASSWORD=
TEST_ADMIN_PASSWORD=
6 changes: 3 additions & 3 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ export class UsersService {
return qb
.where(() => (whereFields.length > 0 ? whereFields : '1 = 0'))
.orWhere(
'unaccent(LOWER("user"."fullName")) ILIKE unaccent(LOWER(:name))',
'unaccent(UPPER("user"."fullName")) ILIKE unaccent(UPPER(:name))',
{ name: `%${fieldName}%` },
)
.orWhere(
'unaccent(LOWER("user"."firstName")) ILIKE unaccent(LOWER(:name))',
'unaccent(UPPER("user"."firstName")) ILIKE unaccent(UPPER(:name))',
{ name: `%${fieldName}%` },
)
.orWhere(
'unaccent(LOWER("user"."lastName")) ILIKE unaccent(LOWER(:name))',
'unaccent(UPPER("user"."lastName")) ILIKE unaccent(UPPER(:name))',
{ name: `%${fieldName}%` },
);
} else {
Expand Down
8 changes: 8 additions & 0 deletions test/admin/users.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ADMIN_EMAIL,
ADMIN_PASSWORD,
APP_URL,
LICENSEE_CASE_ACCENT,
LICENSEE_PERMIT_CODE,
MAILDEV_URL,
} from '../utils/constants';
Expand Down Expand Up @@ -63,6 +64,13 @@ describe('Admin managing users (e2e)', () => {
.then(({ body }) => body.data);
const licenseePartOfName = 'user';
const args = [
{
filter: { name: stringUppercaseUnaccent(LICENSEE_CASE_ACCENT) },
expect: (body: any) =>
expect(
body.data.some((i: any) => i.fullName === LICENSEE_CASE_ACCENT),
).toBeTruthy(),
},
{
filter: { permitCode: licensee.permitCode },
expect: (body: any) =>
Expand Down
29 changes: 13 additions & 16 deletions test/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ config();

export const APP_URL = `http://localhost:${process.env.APP_PORT}`;
export const MAILDEV_URL = `http://${process.env.MAIL_HOST}:${process.env.MAIL_CLIENT_PORT}`;
export const TESTER_EMAIL = 'john.doe@example.com';
export const TESTER_PASSWORD = 'secret';

export const ADMIN_EMAIL = process.env.TEST_ADMIN_EMAIL || 'admin@example.com';
export const ADMIN_PASSWORD = process.env.TEST_ADMIN_PASSWORD || 'secret';
export const ADMIN_2_EMAIL =
process.env.TEST_ADMIN_2_EMAIL || 'admin.test@example.com';
export const ADMIN_2_PASSWORD = process.env.TEST_ADMIN_2_PASSWORD || 'secret';
export const LICENSEE_EMAIL =
process.env.TEST_LICENSEE_EMAIL || 'henrique@example.com';
export const LICENSEE_2_EMAIL =
process.env.TEST_LICENSEE_2_EMAIL || 'marcia@example.com';
export const LICENSEE_2_PERMIT_CODE =
process.env.TEST_LICENSEE_2_PERMIT_CODE || '319274392832023';
export const LICENSEE_CASE_ACCENT =
process.env.TEST_LICENSEE_CASE_ACCENT || 'Márcia Clara Template';
export const LICENSEE_PERMIT_CODE =
process.env.TEST_LICENSEE_PERMIT_CODE || '213890329890312';
export const LICENSEE_PASSWORD = process.env.TEST_LICENSEE_PASSWORD || 'secret';
export const ADMIN_2_EMAIL = 'admin.test@example.com';
export const ADMIN_2_PASSWORD = 'secret';

export const LICENSEE_EMAIL = 'henrique@example.com';
export const LICENSEE_PERMIT_CODE = '213890329890312';
export const LICENSEE_PASSWORD = 'secret';
export const LICENSEE_CASE_ACCENT = 'Márcia Clara Template';

export const LICENSEE_2_EMAIL = 'marcia@example.com';
export const LICENSEE_2_PERMIT_CODE = '319274392832023';
export const LICENSEE_2_PASSWORD = 'secret';

export const MAIL_HOST = process.env.MAIL_HOST;
export const MAIL_PORT = process.env.MAIL_CLIENT_PORT;

0 comments on commit 70039e9

Please sign in to comment.