Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
chungthuang committed Sep 30, 2024
1 parent b6d9412 commit ad83408
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
18 changes: 14 additions & 4 deletions init/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
calendarId: "[email protected]",
discordWebhookUrl: null
},
opportunity : [{
opportunity: [{
title: "test opportunity",
level: "Beginner",
commitmentHoursPerWeek: 2,
Expand All @@ -74,7 +74,12 @@ module.exports = {
],
isHidden: true,
roleCategory: "Development",
roleType: "Back-End Developer"
roleType: "Back-End Developer",
role: {
"id": 0,
"name": "Back-End Developer",
"category": "Development"
}
},
{
title: "test second opportunity",
Expand All @@ -88,7 +93,12 @@ module.exports = {
}
],
isHidden: true,
roleCategory: "Development",
roleType: "Back-End Developer"
roleCategory: "Product / UX",
roleType: "Product Lead",
role: {
"id": 1,
"name": "Product Lead",
"category": "Product / UX"
}
}]
};
43 changes: 19 additions & 24 deletions tests/opportunity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,28 @@ import * as config from '../init/config';
test.describe('/api/opportunities', () => {

test("Get all opportunities", async ({ request }) => {
const opportunityData = await api(request).getData("/api/opportunities");
const opportunityData = await api(request).getData("/api/opportunities?populate=role");

// expect two opportunities to exists
expect(opportunityData.length).toBe(2)

const firstOpportunity = opportunityData[0].attributes;

// expect opportunities have different fields filled
expect(firstOpportunity.title).toBe(config.opportunity[0].title);
expect(firstOpportunity.level).toBe(config.opportunity[0].level);
expect(firstOpportunity.commitmentHoursPerWeek).toBe(config.opportunity[0].commitmentHoursPerWeek);
expect(firstOpportunity.description).toBe(config.opportunity[0].description);
expect(firstOpportunity.isHidden).toBe(config.opportunity[0].isHidden);
expect(firstOpportunity.roleCategory).toBe(config.opportunity[0].roleCategory);
expect(firstOpportunity.roleType).toBe(config.opportunity[0].roleType);

const secondOpportunity = opportunityData[1].attributes;
expect(secondOpportunity.title).toBe(config.opportunity[1].title);
expect(secondOpportunity.level).toBe(config.opportunity[1].level);
expect(secondOpportunity.commitmentHoursPerWeek).toBe(config.opportunity[1].commitmentHoursPerWeek);
expect(secondOpportunity.description).toBe(config.opportunity[1].description);
expect(secondOpportunity.isHidden).toBe(config.opportunity[1].isHidden);
expect(secondOpportunity.roleCategory).toBe(config.opportunity[1].roleCategory);
expect(secondOpportunity.roleType).toBe(config.opportunity[1].roleType);
for (let i = 0; i < 2; i++) {
const opportunity = opportunityData[i].attributes;

// expect opportunities have different fields filled
expect(opportunity.title).toBe(config.opportunity[i].title);
expect(opportunity.level).toBe(config.opportunity[i].level);
expect(opportunity.commitmentHoursPerWeek).toBe(config.opportunity[i].commitmentHoursPerWeek);
expect(opportunity.description).toBe(config.opportunity[i].description);
expect(opportunity.isHidden).toBe(config.opportunity[i].isHidden);
expect(opportunity.roleCategory).toBe(config.opportunity[i].roleCategory);
expect(opportunity.roleType).toBe(config.opportunity[i].roleType);
expect(opportunity.role).toBe(config.opportunity[i].role);

Check failure on line 24 in tests/opportunity.spec.ts

View workflow job for this annotation

GitHub Actions / build

tests/opportunity.spec.ts:7:9 › /api/opportunities › Get all opportunities

1) tests/opportunity.spec.ts:7:9 › /api/opportunities › Get all opportunities ──────────────────── Error: expect(received).toBe(expected) // Object.is equality - Expected - 1 + Received + 1 Object { "category": "Development", - "id": 0, + "id": 1, "name": "Back-End Developer", } 22 | expect(opportunity.roleCategory).toBe(config.opportunity[i].roleCategory); 23 | expect(opportunity.roleType).toBe(config.opportunity[i].roleType); > 24 | expect(opportunity.role).toBe(config.opportunity[i].role); | ^ 25 | } 26 | }); 27 | test("Get opportunity by id", async ({ request }) => { at /home/runner/work/strapiv4/strapiv4/tests/opportunity.spec.ts:24:38
}
});
test("Get opportunity by id", async ({ request }) => {
const opportunityData = await api(request).getData("/api/opportunities/2");
const opportunityData = await api(request).getData("/api/opportunities/2?populate=role");

// expect to receive opportunity filtered by id 2
expect(opportunityData.id).toBe(2);
const opportunity = opportunityData.attributes;
Expand All @@ -44,6 +38,7 @@ test.describe('/api/opportunities', () => {
expect(opportunity.description).toBe(config.opportunity[1].description);
expect(opportunity.isHidden).toBe(config.opportunity[1].isHidden);
expect(opportunity.roleCategory).toBe(config.opportunity[1].roleCategory);
expect(opportunity.roleType).toBe(config.opportunity[1].roleType);
});
expect(opportunity.roleType).toBe(config.opportunity[1].roleType);
expect(opportunity.role).toBe(config.opportunity[1].role);

Check failure on line 42 in tests/opportunity.spec.ts

View workflow job for this annotation

GitHub Actions / build

tests/opportunity.spec.ts:27:9 › /api/opportunities › Get opportunity by id

2) tests/opportunity.spec.ts:27:9 › /api/opportunities › Get opportunity by id ─────────────────── Error: expect(received).toBe(expected) // Object.is equality - Expected - 1 + Received + 1 Object { "category": "Product / UX", - "id": 1, + "id": 2, "name": "Product Lead", } 40 | expect(opportunity.roleCategory).toBe(config.opportunity[1].roleCategory); 41 | expect(opportunity.roleType).toBe(config.opportunity[1].roleType); > 42 | expect(opportunity.role).toBe(config.opportunity[1].role); | ^ 43 | }); 44 | }); at /home/runner/work/strapiv4/strapiv4/tests/opportunity.spec.ts:42:34
});
});

0 comments on commit ad83408

Please sign in to comment.