diff --git a/source/api/tos_api.ts b/source/api/tos_api.ts new file mode 100644 index 0000000..37eb5b4 --- /dev/null +++ b/source/api/tos_api.ts @@ -0,0 +1,15 @@ +import ApiTosVersion from "../models/api/api_tos_version"; +import Http from "../utilities/http"; +import type {ApiTrade, User} from "../models"; + +export default class TosApi { + static getLatest(user: User): Promise { + const url = `${Http.baseUrl()}/tos/latest`; + return Http.get(url, user) as unknown as Promise; + } + + static accept(tosVersionId: number, user: User): Promise { + const url = `${Http.baseUrl()}/tos/${tosVersionId}/accept`; + return Http.post(url, user) as unknown as Promise; + } +} \ No newline at end of file diff --git a/source/models/api/api_tos_version.ts b/source/models/api/api_tos_version.ts new file mode 100644 index 0000000..1ef6278 --- /dev/null +++ b/source/models/api/api_tos_version.ts @@ -0,0 +1,13 @@ +import {DateLike} from "type_aliases"; + +export default class ApiTosVersion { + id: number + createdAt: DateLike + content: string + + constructor({ id, createdAt, content }: Partial = {}) { + this.id = id; + this.createdAt = createdAt; + this.content = content; + } +} diff --git a/tests/api/comment_api_test.ts b/tests/api/comment_api_test.ts index 67f7059..90c2549 100644 --- a/tests/api/comment_api_test.ts +++ b/tests/api/comment_api_test.ts @@ -19,21 +19,8 @@ describe("CommentApi", () => { describe("::getCommentThreads", () => { let author = new ApiUser({email: "some-user@email.com", role: UserRole.USER}); beforeEach(() => { - let response = new ApiCommentThread({ - id: 4, - author, - viewId: 7, - comments: [new ApiComment({ - id: 1, - author, - text: "some text", - commentThreadId: 4, - date: 12345689 - })] - }); - - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/comments/threads`, response); - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/comments/threads?floorId=some-floor&scanDatasetId=some-scan-dataset&viewId=4`, response); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/comments/threads`, 200); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/comments/threads?floorId=some-floor&scanDatasetId=some-scan-dataset&viewId=4`, 200); }); it("makes a call to the endpoint", () => { @@ -99,19 +86,7 @@ describe("CommentApi", () => { })] }); - fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/comments/threads`, - new ApiCommentThread({ - id: 4, - author, - viewId: 7, - comments: [new ApiComment({ - id: 1, - author, - text: "some text", - commentThreadId: 4, - date: 12345689 - })] - })); + fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/comments/threads`, 200); }); it("makes a call to the endpoint", () => { @@ -157,15 +132,7 @@ describe("CommentApi", () => { date: 12345689 }); - fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/comments/threads/4`, - new ApiComment({ - id: 1, - author, - text: "some text", - commentThreadId: 4, - date: 12345689 - }) - ); + fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/comments/threads/4`, 200); }); it("makes a call to the endpoint", () => { @@ -213,15 +180,7 @@ describe("CommentApi", () => { date: 12345689 }); - fetchMock.put(`${Http.baseUrl()}/projects/some-project-id/comments/1`, - new ApiComment({ - id: 1, - author, - text: "some updated text", - commentThreadId: 4, - date: 12345689 - }) - ); + fetchMock.put(`${Http.baseUrl()}/projects/some-project-id/comments/1`, 200); }); it("makes a call to the endpoint", () => { @@ -256,4 +215,4 @@ describe("CommentApi", () => { }); }); -}); \ No newline at end of file +}); diff --git a/tests/api/integrations_api_test.ts b/tests/api/integrations_api_test.ts index 41842f2..ae37ddf 100644 --- a/tests/api/integrations_api_test.ts +++ b/tests/api/integrations_api_test.ts @@ -36,16 +36,7 @@ describe("IntegrationsApi", () => { describe("::saveIntegrationCredentials", () => { beforeEach(() => { - let response = new ApiIntegrationCredentials({ - authorId: 1, - firebaseOrganizationId: "some-org-id", - firebaseProjectId: "some-project-id", - username: "some-username", - password: "some-password", - credentialsType: ApiIntegrationCredentialsType.DRONE_DEPLOY - }); - - fetchMock.put(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY`, response); + fetchMock.put(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY`, 200); }); it("makes a call to the endpoint", () => { @@ -90,21 +81,7 @@ describe("IntegrationsApi", () => { describe("::getIntegrationProjectsForCredentials", () => { beforeEach(() => { - let response = [new ApiIntegrationProject({ - id: 1, - integrationCredentialsId: 2, - externalName: "Some Name", - externalId: "some-id" - }), - new ApiIntegrationProject({ - id: 2, - integrationCredentialsId: 2, - externalName: "Some Other Name", - externalId: "some-other-id" - }) - ]; - - fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/projects`, response); + fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/projects`, 200); }); it("makes a call to the endpoint", () => { @@ -141,16 +118,7 @@ describe("IntegrationsApi", () => { describe("::getIntegrationCredentials", () => { beforeEach(() => { - let response = new ApiIntegrationCredentials({ - authorId: 1, - firebaseOrganizationId: "some-org-id", - firebaseProjectId: "some-project-id", - username: "some-username", - password: "some-password", - credentialsType: ApiIntegrationCredentialsType.DRONE_DEPLOY - }); - - fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY`, response); + fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY`, 200); }); it("makes a call to the endpoint", () => { @@ -187,16 +155,7 @@ describe("IntegrationsApi", () => { describe("::getProjectIntegrationCredentials", () => { beforeEach(() => { - let response = [new ApiIntegrationCredentials({ - authorId: 1, - firebaseOrganizationId: "some-org-id", - firebaseProjectId: "some-project-id", - username: "some-username", - password: "some-password", - credentialsType: ApiIntegrationCredentialsType.DRONE_DEPLOY - })]; - - fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials`, response); + fetchMock.get(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials`, 200); }); it("makes a call to the endpoint", () => { @@ -231,11 +190,7 @@ describe("IntegrationsApi", () => { describe("::syncIntegrationProjects", () => { beforeEach(() => { - let response = new ApiRunningProcess({ - id: 1, - name: "some-process" - }); - fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/sync-projects`, response); + fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/sync-projects`, 200); }); it("makes a call to the endpoint", () => { @@ -272,11 +227,7 @@ describe("IntegrationsApi", () => { describe("::syncIntegrationPhotoAreas", () => { beforeEach(() => { - let response = new ApiRunningProcess({ - id: 1, - name: "some-process" - }); - fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/sync-photo-areas`, response); + fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/credentials/DRONE_DEPLOY/sync-photo-areas`, 200); }); it("makes a call to the endpoint", () => { @@ -313,7 +264,7 @@ describe("IntegrationsApi", () => { describe("::updateProjectIntegrationProject", () => { beforeEach(() => { - fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/set-integration-project`, ""); + fetchMock.post(`${Http.baseUrl()}/integrations/organizations/some-org-id/projects/some-project-id/set-integration-project`, 200); }); it("makes a call to the endpoint", () => { @@ -370,7 +321,7 @@ describe("IntegrationsApi", () => { describe("::checkProcoreAccessToken", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/access-token?procore-access-token=some-procore-access-token`, - {status: 200, body: {expiresInSeconds: 3600}}); + 200); }); it("includes auth headers and makes a request to check access token", () => { @@ -412,9 +363,9 @@ describe("IntegrationsApi", () => { describe("::getProcoreProjects", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/projects?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-project"]}); + 200); fetchMock.get(`${Http.baseUrl()}/integrations/procore/projects?procore-access-token=some-procore-access-token&companyId=some-company-id`, - {status: 200, body: ["some-procore-project"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -493,7 +444,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreCompanies", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/companies?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-company"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -535,7 +486,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreObservationTypes", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/observation-types?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-observation-type"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -588,7 +539,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreObservationAssignees", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/observation-assignees?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-observation-assignees"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -681,8 +632,7 @@ describe("IntegrationsApi", () => { fetchMock.get( `${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/procore-tools-permissions?procore-access-token=some-procore-access-token`, - {status: 200, body: mockResponse} - ); + {status: 200, body: mockResponse}); }); it("includes auth headers and makes a request to the gateway", () => { @@ -759,7 +709,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreRfiAssignees", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/rfi-assignees?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-assignees"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -823,7 +773,7 @@ describe("IntegrationsApi", () => { describe("::getRfiManagers", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/rfi-managers?procore-access-token=some-procore-access-token`, - {status: 200, body: ["some-procore-assignees"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -1401,7 +1351,7 @@ describe("IntegrationsApi", () => { describe("::getAutodeskAccessToken", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/autodesk/access-token?code=some-code&redirect-uri=some-redirect-uri`, - {status: 200, body: {access_token: "some-access-token"}}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -1467,7 +1417,7 @@ describe("IntegrationsApi", () => { describe("::getAutoDeskHubs", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/autodesk/hubs?access-token=some-access-token`, - {status: 200, body: ["some-autodesk-hubs"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -1514,7 +1464,7 @@ describe("IntegrationsApi", () => { describe("::getAutoDeskProjects", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/autodesk/projects?access-token=some-access-token&hubId=some-hub-id`, - {status: 200, body: ["some-autodesk-project"]}); + 200); } ); @@ -1579,7 +1529,7 @@ describe("IntegrationsApi", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/autodesk/issue-types?access-token=some-access-token&projectId=some-project-id`, - {status: 200, body: ["some-autodesk-issue-type"]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -1632,10 +1582,7 @@ describe("IntegrationsApi", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/autodesk/assignees?access-token=some-access-token&projectId=some-project-id`, - {status: 200, body: [ - {name: "John Doe", autodeskId: "ABC123"}, - {name: "Jane Smith", autodeskId: "XYZ789"} - ]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2190,10 +2137,8 @@ describe("IntegrationsApi", () => { describe("::getReviztoAccessToken", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/integrations/revizto/access-token?code=some-code®ion=some-region`, { - status: 200, - body: { access_token: "some-access-token", token_type: "Bearer", expires_in: "3600", refresh_token: "some-refresh-token" } - }); + fetchMock.get(`${Http.baseUrl()}/integrations/revizto/access-token?code=some-code®ion=some-region`, + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2255,44 +2200,8 @@ describe("IntegrationsApi", () => { describe("::getReviztoData", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/integrations/revizto/get-data?access-token=some-access-token®ion=some-region`, { - status: 200, - body: { - userEmail: "some-user-email@example.com", - hubs: [ - { - hubId: "some-hub-id", - hubName: "Some Hub Name", - hubUuid: "some-hub-uuid", - projects: [ - { - projectTitle: "Some Project Title 1", - projectUuid: "some-project-uuid-1", - projectId: "some-project-id-1", - statuses: [ - { - statusName: "Some Status 1", - statusUuid: "some-status-uuid-1" - } - ], - types: [ - { - typeName: "Some Type 1", - typeUuid: "some-type-uuid-1" - } - ], - assignees: [ - { - assigneeEmail: "some-email-1@example.com", - asigneeUuid: "some-assignee-uuid-1" - } - ] - } - ] - } - ] - } - }); + fetchMock.get(`${Http.baseUrl()}/integrations/revizto/get-data?access-token=some-access-token®ion=some-region`, + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2354,10 +2263,7 @@ describe("IntegrationsApi", () => { describe("::getPowerBIAccessToken", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/integrations/powerbi/accessToken`, { - status: 200, - body: { access_token: "some-access-token", token_type: "Bearer", expires_in: "3600", refresh_token: "some-refresh-token" } - }); + fetchMock.get(`${Http.baseUrl()}/integrations/powerbi/accessToken`, 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2379,10 +2285,7 @@ describe("IntegrationsApi", () => { const url = `${Http.baseUrl()}/integrations/powerbi/embedToken/groups/${groupId}/reports/${reportId}`; beforeEach(() => { - fetchMock.get(url, { - status: 200, - body: { token: "some-embed-token", expiration: "2024-12-31T23:59:59Z" } - }); + fetchMock.get(url, 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2655,7 +2558,7 @@ describe("IntegrationsApi", () => { describe("::getAllCreatedIssuesForDeviatedElements", () => { beforeEach(() => { fetchMock.post(`${Http.baseUrl()}/integrations/tools/issues`, - [{"id":1, "status":"some-status"}]); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2676,7 +2579,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreTradesForCoordinateIssue", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/trades?procore-access-token=some-procore-access-token`, - {status: 200, body: [{id: 1, name: "Electrical", active: true}, {id: 2, name: "Plumbing", active: true}]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2728,7 +2631,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreLocationsForCoordinateIssue", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/locations?procore-access-token=some-procore-access-token`, - {status: 200, body: [{id: 1, name: "Building A", parent_id: null}, {id: 2, name: "Building B", parent_id: 1}]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { @@ -2791,7 +2694,7 @@ describe("IntegrationsApi", () => { describe("::getProcoreCoordinationIssueAssigness", () => { beforeEach(() => { fetchMock.get(`${Http.baseUrl()}/integrations/procore/some-company-id/some-project-id/coordination-issue-assignees?procore-access-token=some-procore-access-token`, - {status: 200, body: [{id: 1, name: "Assignee 1"}, {id: 2, name: "Assignee 2"}]}); + 200); }); it("includes auth headers and makes a request to the gateway", () => { diff --git a/tests/api/project_summary_api_test.ts b/tests/api/project_summary_api_test.ts index bc38f61..596bef4 100644 --- a/tests/api/project_summary_api_test.ts +++ b/tests/api/project_summary_api_test.ts @@ -75,12 +75,7 @@ describe("ProjectSummaryApi", () => { describe("::createProjectArea", () => { beforeEach(() => { - fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/areas`, new ApiProjectArea({ - id: 12, - modelElementId: 1, - floorId: 7, - firebaseFloorId: "some-floor-id" - })); + fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/areas`, 200); }); it("makes a call to the endpoint", () => { @@ -122,12 +117,7 @@ describe("ProjectSummaryApi", () => { describe("::updateProjectArea", () => { beforeEach(() => { - fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/12`, new ApiProjectArea({ - id: 12, - modelElementId: 1, - floorId: 7, - firebaseFloorId: "some-floor-id" - })); + fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/12`, 200); }); it("makes a call to the endpoint", () => { @@ -169,7 +159,7 @@ describe("ProjectSummaryApi", () => { }); describe("::updateProjectAreaProgress", () => { - let projectAreaId, response; + let projectAreaId; beforeEach(() => { projectAreaId = 1; let projectAreaProgress = new ApiProjectAreaWorkPackage({ @@ -182,12 +172,7 @@ describe("ProjectSummaryApi", () => { start: null, completion: null }); - response = new ApiProjectArea({ - id: 12, - modelElementId: projectAreaId, - workPackages: [projectAreaProgress] - }); - fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/${projectAreaId}`, response); + fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/${projectAreaId}`, 200); }); it("makes a call to the endpoint", () => { @@ -249,16 +234,7 @@ describe("ProjectSummaryApi", () => { describe("::createProjectAreaWorkPackage", () => { beforeEach(() => { - fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/areas/12/work-packages`, new ApiProjectAreaWorkPackage({ - id: 54, - projectWorkPackageId: 5, - workPackageId: 3, - status: "started", - expectedStart: null, - expectedCompletion: null, - start: null, - completion: null - })); + fetchMock.post(`${Http.baseUrl()}/projects/some-project-id/areas/12/work-packages`, 200); }); it("makes a call to the endpoint", () => { @@ -311,16 +287,7 @@ describe("ProjectSummaryApi", () => { describe("::updateProjectAreaWorkPackages", () => { beforeEach(() => { - fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/12/work-packages`, [new ApiProjectAreaWorkPackage({ - id: 54, - projectWorkPackageId: 5, - workPackageId: 3, - status: "started", - expectedStart: null, - expectedCompletion: null, - start: null, - completion: null - })]); + fetchMock.patch(`${Http.baseUrl()}/projects/some-project-id/areas/12/work-packages`, 200); }); it("makes a call to the endpoint", () => { @@ -372,7 +339,7 @@ describe("ProjectSummaryApi", () => { }); describe("::getProjectArea", () => { - let projectAreaId, response; + let projectAreaId; beforeEach(() => { projectAreaId = 1; let projectAreaProgress = new ApiProjectAreaWorkPackage({ @@ -386,12 +353,7 @@ describe("ProjectSummaryApi", () => { start: null, completion: null }); - response = new ApiProjectArea({ - id: 12, - modelElementId: projectAreaId, - workPackages: [projectAreaProgress] - }); - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/${projectAreaId}`, response); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/${projectAreaId}`, 200); }); it("makes a call to the endpoint", () => { @@ -421,12 +383,7 @@ describe("ProjectSummaryApi", () => { describe("::listProjectAreas", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas`, [new ApiProjectArea({ - id: 12, - modelElementId: 3, - workPackages: [], - progress: [] - })]); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas`, 200); }); it("makes a call to the endpoint", () => { @@ -454,10 +411,7 @@ describe("ProjectSummaryApi", () => { describe("::listProjectAreaWorkPackages", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/7/work-packages`, [new ApiProjectAreaWorkPackage({ - id: 12, - projectAreaId: 7 - })]); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/7/work-packages`, 200); }); it("makes a call to the endpoint", () => { @@ -487,13 +441,7 @@ describe("ProjectSummaryApi", () => { describe("::listProjectAreaWorkPackagesForProject", () => { beforeEach(() => { - fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/work-packages`, [new ApiProjectAreaWorkPackage({ - id: 12, - projectAreaId: 3 - }), new ApiProjectAreaWorkPackage({ - id: 13, - projectAreaId: 4 - })]); + fetchMock.get(`${Http.baseUrl()}/projects/some-project-id/areas/work-packages`, 200); }); it("makes a call to the endpoint", () => { diff --git a/tests/api/tos_api_test.ts b/tests/api/tos_api_test.ts new file mode 100644 index 0000000..cd96ab8 --- /dev/null +++ b/tests/api/tos_api_test.ts @@ -0,0 +1,74 @@ +import {describe} from "mocha"; +import {expect} from "chai"; +import fetchMock from "fetch-mock"; + +import TosApi from "../../source/api/tos_api"; +import { + ApiComment, + ApiCommentThread, + ApiUser, + User, + UserRole, + UserAuthType, GATEWAY_JWT, USER +} from "../../source"; +import Http from "../../source/utilities/http"; +import ApiTosVersion from "../../source/models/api/api_tos_version"; +import PipelineApi from "../../source/api/pipeline_api"; + +describe("TosApi", () => { + let user: User; + + beforeEach(() => { + fetchMock.resetBehavior(); + user = { + authType: UserAuthType.FIREBASE, + firebaseUser: { + uid: "some-uid", + role: UserRole.SUPERADMIN, + idToken: "some-firebase.id.token" + } + }; + }); + + describe("::getLatest", () => { + beforeEach(() => { + fetchMock.get(`${Http.baseUrl()}/tos/latest`, 200); + }); + + it("includes the authorization headers", () => { + return TosApi.getLatest({ + authType: GATEWAY_JWT, + gatewayUser: {idToken: "some-firebase.id.token", role: USER} + }).then(() => { + expect(fetchMock.lastOptions().headers.Authorization).to.eq("Bearer some-firebase.id.token"); + }).catch(console.error); + }); + + it("makes a call to the endpoint", () => { + return TosApi.getLatest(user).then(latest => { + expect(fetchMock.lastCall()[0]).to.eq(`${Http.baseUrl()}/tos/latest`); + }).catch(console.error); + }); + }); + + describe("::accept", () => { + beforeEach(() => { + fetchMock.post(`${Http.baseUrl()}/tos/123/accept`, 200); + }); + + it("includes the authorization headers", () => { + return TosApi.accept(123, { + authType: GATEWAY_JWT, + gatewayUser: {idToken: "some-firebase.id.token", role: USER} + }).then(() => { + expect(fetchMock.lastOptions().headers.Authorization).to.eq("Bearer some-firebase.id.token"); + }).catch(console.error); + }); + + it("makes a call to the endpoint", () => { + return TosApi.accept(123, user).then(latest => { + expect(fetchMock.lastCall()[0]).to.eq(`${Http.baseUrl()}/tos/123/accept`); + }).catch(console.error); + }); + }); +});