-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): added a certification authority creation test
- Loading branch information
Showing
1 changed file
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
/** | ||
* @jest-environment ./test/fastify-test-env.ts | ||
*/ | ||
import { | ||
Account, | ||
CertificationAuthority, | ||
|
@@ -11,6 +8,10 @@ import { prismaClient } from "../../prisma/client"; | |
import { CERTIFICATION_AUTHORITY_STRUCTURES } from "../../test/fixtures"; | ||
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper"; | ||
import { injectGraphql } from "../../test/helpers/graphql-helper"; | ||
import { buildApp } from "../../infra/server/app"; | ||
import keycloakPluginMock from "../../test/mocks/keycloak-plugin.mock"; | ||
|
||
import * as createAccount from "../account/features/createAccount"; | ||
|
||
const CERTIFICATION_AUTHORITY_KEYCLOAK_ID = | ||
"3c6d4571-da18-49a3-90e5-cc83ae7446bf"; | ||
|
@@ -26,6 +27,9 @@ let certificationAuthorityLocalAccount1 = | |
{} as CertificationAuthorityLocalAccount; | ||
|
||
beforeAll(async () => { | ||
const app = await buildApp({ keycloakPluginMock }); | ||
(global as any).fastify = app; | ||
|
||
certificationAccountAutorityAccount = await prismaClient.account.create({ | ||
data: { | ||
email: "[email protected]", | ||
|
@@ -79,3 +83,41 @@ test("should return an exisiting certification local account list of 1 item for | |
.certificationAuthorityLocalAccounts, | ||
).toMatchObject([{ id: certificationAuthorityLocalAccount1.id }]); | ||
}); | ||
|
||
test("should create a certification authority", async () => { | ||
jest | ||
.spyOn(createAccount, "createAccount") | ||
.mockImplementation(() => Promise.resolve({} as Account)); | ||
|
||
const resp = await injectGraphql({ | ||
fastify: (global as any).fastify, | ||
authorization: authorizationHeaderForUser({ | ||
role: "admin", | ||
keycloakId: "3c6d4571-da18-49a3-90e5-cc83ae7446bf", | ||
}), | ||
payload: { | ||
requestType: "mutation", | ||
endpoint: "certification_authority_createCertificationAuthority", | ||
arguments: { | ||
input: { | ||
label: "Mon autorite de certification", | ||
certificationAuthorityStructureId: | ||
CERTIFICATION_AUTHORITY_STRUCTURES.UIMM.id, | ||
contactEmail: "[email protected]", | ||
contactFullName: "Monieur test test", | ||
accountEmail: "[email protected]", | ||
accountFirstname: "testFirstname", | ||
accountLastname: "testLastname", | ||
certificationIds: [], | ||
}, | ||
}, | ||
returnFields: "{id}", | ||
}, | ||
}); | ||
expect(resp.statusCode).toEqual(200); | ||
const obj = resp.json(); | ||
expect(resp.json()).not.toHaveProperty("errors"); | ||
expect( | ||
obj.data.certification_authority_createCertificationAuthority.id, | ||
).not.toBeNull(); | ||
}); |