Skip to content

Commit

Permalink
Merge pull request #2146 from CAFECA-IO/fix/fido_unittest
Browse files Browse the repository at this point in the history
fix:fido_signin and unittest
  • Loading branch information
Luphia authored Aug 21, 2024
2 parents 06c5dca + 8794e8c commit acfafd3
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iSunFA",
"version": "0.8.0+20",
"version": "0.8.0+21",
"private": false,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion prisma/seed_json/employee_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"employeeId": 1001,
"projectId": 1000,
"startDate": 1635724800,
"endDate": 1635811200,
"endDate": null,
"createdAt": 1635724800,
"updatedAt": 1635724800
}
Expand Down
60 changes: 57 additions & 3 deletions prisma/seed_json/milestone.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"id":1015,
"id": 1015,
"projectId": 1001,
"startDate": 1709578219,
"endDate": 1712256619,
Expand Down Expand Up @@ -81,7 +81,7 @@
"updatedAt": 1717637165
},
{
"id":1014,
"id": 1014,
"projectId": 1007,
"startDate": 1717637165,
"endDate": 1718179676,
Expand Down Expand Up @@ -142,5 +142,59 @@
"status": "Archived",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1016,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Designing",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1017,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Beta Testing",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1018,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Develop",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1019,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Selling",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1020,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Sold",
"createdAt": 1709578219,
"updatedAt": 1709578219
},
{
"id": 1021,
"projectId": 1009,
"startDate": 0,
"endDate": 0,
"status": "Archived",
"createdAt": 1709578219,
"updatedAt": 1709578219
}
]
]
11 changes: 11 additions & 0 deletions prisma/seed_json/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,16 @@
"createdAt": 1651368365,
"updatedAt": 1651368365,
"deletedAt": null
},
{
"id": 1009,
"companyId": 1000,
"name": "Test update Project",
"completedPercent": 83,
"stage": "Beta Testing",
"imageId": "TP",
"createdAt": 1651368365,
"updatedAt": 1651368365,
"deletedAt": null
}
]
10 changes: 7 additions & 3 deletions src/lib/utils/repo/authentication.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { timestampInSeconds } from '@/lib/utils/common';

export async function getUserByCredential(
credentialId: string
): Promise<(Authentication & { user: User }) | null> {
let user: (Authentication & { user: User }) | null = null;
): Promise<(Authentication & { user: User & { userAgreements: UserAgreement[] } }) | null> {
let user: (Authentication & { user: User & { userAgreements: UserAgreement[] } }) | null = null;
if (credentialId.trim() !== '') {
user = await prisma.authentication.findUnique({
where: {
credentialId,
OR: [{ deletedAt: 0 }, { deletedAt: null }],
},
include: {
user: true,
user: {
include: {
userAgreements: true,
},
},
},
});
}
Expand Down
12 changes: 5 additions & 7 deletions src/lib/utils/repo/employee.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,11 @@ export async function getProjectsByEmployeeId(employeeIdNumber: number) {
employeeId: employeeIdNumber,
endDate: null,
},
select: {
project: {
select: {
id: true,
name: true,
},
},
include: {
project: true,
},
orderBy: {
startDate: 'asc',
},
});
return projects;
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils/repo/profit_comparison.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export async function getProjectLists(companyId: number) {
where: {
companyId,
},
orderBy: {
name: 'asc',
},
});
}

Expand Down
6 changes: 2 additions & 4 deletions src/lib/utils/repo_test/employee.repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,11 @@ describe('Employee Repository Tests', () => {
});
});
describe('getProjectsByEmployeeId', () => {
// TODO (20240820 - Jacky): Fix this test
xit('should get projects by employee id', async () => {
const employeeId = 1000;
it('should get projects by employee id', async () => {
const employeeId = 1001;
const projectsFromDb = await getProjectsByEmployeeId(employeeId);
expect(projectsFromDb).toBeDefined();
expect(Array.isArray(projectsFromDb)).toBe(true);
expect(projectsFromDb.length).toBeGreaterThan(0);
expect(projectsFromDb[0].project.id).toEqual(employeeProjects[0].projectId);
});
});
Expand Down
12 changes: 12 additions & 0 deletions src/lib/utils/repo_test/trasaction_test/project_members.tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe('ProjectMembers Transaction Tests', () => {
});
expect(existingMembers.length).toBe(2);
await updateProjectMembers(testProjectId, memberIdList); // Reset the members
await prisma.employeeProject.deleteMany({
where: {
projectId: testProjectId,
employeeId: {
in: [1000, 1001, 1002],
},
endDate: { not: null },
id: {
gte: 10000000,
},
},
});
}, 10000);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { formatMilestoneList } from '@/lib/utils/formatter/milestone.formatter';
import { IMilestone } from '@/interfaces/project';

let milestoneList: IMilestone[] = [];
const testProjectId = 1000;
const testProjectId = 1009;

beforeAll(async () => {
const listedMilestone = await listProjectMilestone(testProjectId);
milestoneList = formatMilestoneList(listedMilestone);
});

describe('Project Milestone Tests', () => {
const defaultStage = 'Beta Testing';
const updateStage = 'Sold';
const defaultStage = 'Develop';
const updateStage = 'Selling';
const now = Date.now();
const nowTimestamp = timestampInSeconds(now);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/api/v1/sign_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getSession, setSession } from '@/lib/utils/session';
import { useInvitation } from '@/lib/utils/invitation';
import { verifyChallengeTimestamp } from '@/lib/utils/authorization';
import { getUserByCredential } from '@/lib/utils/repo/authentication.repo';
import { formatUser } from '@/lib/utils/formatter/user.formatter';

async function authenticateUser(
authentication: AuthenticationEncoded,
Expand Down Expand Up @@ -38,6 +39,7 @@ async function authenticateUser(
};
try {
await server.verifyAuthentication(authentication, registeredCredential, expected);
user = formatUser(getUser.user);
} catch (error) {
isValid = false;
user = null;
Expand Down

0 comments on commit acfafd3

Please sign in to comment.