Skip to content

Commit

Permalink
feat(component): Create a reusable component for role
Browse files Browse the repository at this point in the history
  • Loading branch information
chungthuang committed Sep 30, 2024
1 parent 8f6c38b commit a395148
Show file tree
Hide file tree
Showing 6 changed files with 213 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": 1,
"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": 2,
"name": "Product Lead",
"category": "Product / UX"
}
}]
};
5 changes: 5 additions & 0 deletions src/api/opportunity/content-types/opportunity/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
],
"required": true,
"default": "Front-End Developer"
},
"role": {
"type": "component",
"repeatable": false,
"component": "role.role"
}
}
}
22 changes: 22 additions & 0 deletions src/components/role/role.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"collectionName": "components_role_roles",
"info": {
"displayName": "role"
},
"options": {},
"attributes": {
"category": {
"type": "enumeration",
"enum": [
"Product / UX",
"Development",
"QA",
"Operations",
"Other"
]
},
"name": {
"type": "string"
}
}
}
45 changes: 21 additions & 24 deletions tests/opportunity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@ 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.name).toBe(config.opportunity[i].role.name);
expect(opportunity.role.category).toBe(config.opportunity[i].role.category);
}
});
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 +39,8 @@ 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.name).toBe(config.opportunity[1].role.name);
expect(opportunity.role.category).toBe(config.opportunity[1].role.category);
});
});
14 changes: 14 additions & 0 deletions types/generated/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ export interface RepoChangesRepoChanges extends Schema.Component {
};
}

export interface RoleRole extends Schema.Component {
collectionName: 'components_role_roles';
info: {
displayName: 'role';
};
attributes: {
category: Attribute.Enumeration<
['Product / UX', 'Development', 'QA', 'Operations', 'Other']
>;
name: Attribute.String;
};
}

export interface SkillsSkills extends Schema.Component {
collectionName: 'components_skills_skills';
info: {
Expand Down Expand Up @@ -309,6 +322,7 @@ declare module '@strapi/types' {
'project.project-milestones': ProjectProjectMilestones;
'project.task': ProjectTask;
'repo-changes.repo-changes': RepoChangesRepoChanges;
'role.role': RoleRole;
'skills.skills': SkillsSkills;
}
}
Expand Down
137 changes: 137 additions & 0 deletions types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,98 @@ export interface AdminTransferTokenPermission extends Schema.CollectionType {
};
}

export interface AdminWorkflow extends Schema.CollectionType {
collectionName: 'strapi_workflows';
info: {
name: 'Workflow';
description: '';
singularName: 'workflow';
pluralName: 'workflows';
displayName: 'Workflow';
};
pluginOptions: {
'content-manager': {
visible: false;
};
'content-type-builder': {
visible: false;
};
};
attributes: {
name: Attribute.String & Attribute.Required & Attribute.Unique;
stages: Attribute.Relation<
'admin::workflow',
'oneToMany',
'admin::workflow-stage'
>;
contentTypes: Attribute.JSON & Attribute.Required & Attribute.DefaultTo<[]>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'admin::workflow',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'admin::workflow',
'oneToOne',
'admin::user'
> &
Attribute.Private;
};
}

export interface AdminWorkflowStage extends Schema.CollectionType {
collectionName: 'strapi_workflows_stages';
info: {
name: 'Workflow Stage';
description: '';
singularName: 'workflow-stage';
pluralName: 'workflow-stages';
displayName: 'Stages';
};
options: {
version: '1.1.0';
};
pluginOptions: {
'content-manager': {
visible: false;
};
'content-type-builder': {
visible: false;
};
};
attributes: {
name: Attribute.String;
color: Attribute.String & Attribute.DefaultTo<'#4945FF'>;
workflow: Attribute.Relation<
'admin::workflow-stage',
'manyToOne',
'admin::workflow'
>;
permissions: Attribute.Relation<
'admin::workflow-stage',
'manyToMany',
'admin::permission'
>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'admin::workflow-stage',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'admin::workflow-stage',
'oneToOne',
'admin::user'
> &
Attribute.Private;
};
}

export interface PluginUploadFile extends Schema.CollectionType {
collectionName: 'files';
info: {
Expand Down Expand Up @@ -1280,6 +1372,7 @@ export interface ApiOpportunityOpportunity extends Schema.CollectionType {
> &
Attribute.Required &
Attribute.DefaultTo<'Front-End Developer'>;
role: Attribute.Component<'role.role'>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
publishedAt: Attribute.DateTime;
Expand Down Expand Up @@ -1564,6 +1657,47 @@ export interface ApiTeamMembershipTeamMembership extends Schema.CollectionType {
};
}

export interface AdminAuditLog extends Schema.CollectionType {
collectionName: 'strapi_audit_logs';
info: {
singularName: 'audit-log';
pluralName: 'audit-logs';
displayName: 'Audit Log';
};
options: {
draftAndPublish: false;
timestamps: false;
};
pluginOptions: {
'content-manager': {
visible: false;
};
'content-type-builder': {
visible: false;
};
};
attributes: {
action: Attribute.String & Attribute.Required;
date: Attribute.DateTime & Attribute.Required;
user: Attribute.Relation<'admin::audit-log', 'oneToOne', 'admin::user'>;
payload: Attribute.JSON;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'admin::audit-log',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'admin::audit-log',
'oneToOne',
'admin::user'
> &
Attribute.Private;
};
}

declare module '@strapi/types' {
export module Shared {
export interface ContentTypes {
Expand All @@ -1574,6 +1708,8 @@ declare module '@strapi/types' {
'admin::api-token-permission': AdminApiTokenPermission;
'admin::transfer-token': AdminTransferToken;
'admin::transfer-token-permission': AdminTransferTokenPermission;
'admin::workflow': AdminWorkflow;
'admin::workflow-stage': AdminWorkflowStage;
'plugin::upload.file': PluginUploadFile;
'plugin::upload.folder': PluginUploadFolder;
'plugin::users-permissions.permission': PluginUsersPermissionsPermission;
Expand All @@ -1599,6 +1735,7 @@ declare module '@strapi/types' {
'api::sendmail.sendmail': ApiSendmailSendmail;
'api::subscription.subscription': ApiSubscriptionSubscription;
'api::team-membership.team-membership': ApiTeamMembershipTeamMembership;
'admin::audit-log': AdminAuditLog;
}
}
}

0 comments on commit a395148

Please sign in to comment.