Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add created date to user #76

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions migrations/1695922686467-add date to user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class addDateToUser1695922686467 implements MigrationInterface {
name = 'addDateToUser1695922686467';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "user" ADD "createdDate" TIMESTAMP NOT NULL DEFAULT now()`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "createdDate"`);
}
}
1 change: 1 addition & 0 deletions src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

const serviceMock: Partial<AuthService> = {
Expand Down
1 change: 1 addition & 0 deletions src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-28'),
};

const mockCognitoService = {
Expand Down
1 change: 1 addition & 0 deletions src/auth/guards/roles.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser = (role: Role): User => ({
firstName: 'first',
lastName: 'last',
role,
createdDate: new Date('2023-09-28'),
});

const mockContext = (user?: User): Partial<ExecutionContext> => ({
Expand Down
1 change: 1 addition & 0 deletions src/auth/middleware/authentication.middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mockUser: User = {
firstName: 'first',
lastName: 'last',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

const mockAuthService: Partial<AuthService> = {
Expand Down
5 changes: 4 additions & 1 deletion src/user/types/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsEmail } from 'class-validator';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
import { Role } from './role';

@Entity()
Expand All @@ -25,4 +25,7 @@ export class User {
default: Role.ADMIN,
})
role: Role;

@CreateDateColumn()
createdDate: Date;
}
3 changes: 3 additions & 0 deletions src/user/types/user.examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const ADMIN_1: User = {
lastName: 'last',
email: 'test@test.com',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const ADMIN_2: User = {
Expand All @@ -15,6 +16,7 @@ export const ADMIN_2: User = {
lastName: 'last',
email: 'already@exists.com',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const RESEARCHER_1: User = {
Expand All @@ -23,4 +25,5 @@ export const RESEARCHER_1: User = {
lastName: 'last',
email: 'researcher@test.com',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-24'),
};
1 change: 1 addition & 0 deletions src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const mockUser: User = {
firstName: 'test',
lastName: 'user',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

const listMockUsers: User[] = [mockUser];
Expand Down
2 changes: 2 additions & 0 deletions src/user/user.examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export const userExamples = [
role: Role.ADMIN,
firstName: 'admin',
lastName: 'user',
createdDate: new Date('2023-09-24'),
},
{
email: 'c4cneu.jpal+researcher@gmail.com',
role: Role.RESEARCHER,
firstName: 'researcher',
lastName: 'user',
createdDate: new Date('2023-09-24'),
},
];
2 changes: 2 additions & 0 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const mockUser: User = {
firstName: 'William',
lastName: 'user',
role: Role.ADMIN,
createdDate: new Date('2023-09-24'),
};

export const mockResearcher: User = {
Expand All @@ -22,6 +23,7 @@ export const mockResearcher: User = {
firstName: 'Paige',
lastName: 'Turner',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-24'),
};

const listMockUsers: User[] = [mockUser, mockResearcher];
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const initialUser: Omit<User, 'id'> = {
firstName: 'first',
lastName: 'last',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

describe('Example e2e', () => {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/survey.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const mockUser2: User = {
firstName: 'first',
lastName: 'last',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-28'),
};

describe('Survey e2e', () => {
Expand Down
19 changes: 17 additions & 2 deletions test/e2e/users.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ const initialResearcherUser: Omit<User, 'id'> = {
firstName: 'test',
lastName: 'researcher',
role: Role.RESEARCHER,
createdDate: new Date('2023-09-28'),
};

const adminUser1: Omit<User, 'id'> = {
email: 'cooladmin@test.com',
firstName: 'test',
lastName: 'admin1',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

const adminUser2: Omit<User, 'id'> = {
email: 'lameadmin@test.com',
firstName: 'test',
lastName: 'admin2',
role: Role.ADMIN,
createdDate: new Date('2023-09-28'),
};

describe('Users e2e', () => {
Expand Down Expand Up @@ -110,8 +113,20 @@ describe('Users e2e', () => {

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
expect.objectContaining(adminUser1),
expect.objectContaining(adminUser2),
expect.objectContaining({
email: 'cooladmin@test.com',
firstName: 'test',
lastName: 'admin1',
role: Role.ADMIN,
createdDate: new Date('2023-09-28').toISOString(),
}),
expect.objectContaining({
email: 'lameadmin@test.com',
firstName: 'test',
lastName: 'admin2',
role: Role.ADMIN,
createdDate: new Date('2023-09-28').toISOString(),
}),
]);
});

Expand Down
Loading