Skip to content

Commit

Permalink
feat(api): added a certification authority creation test
Browse files Browse the repository at this point in the history
  • Loading branch information
agarbe committed Nov 15, 2024
1 parent 389e84b commit edbbb57
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* @jest-environment ./test/fastify-test-env.ts
*/
import {
Account,
CertificationAuthority,
Expand All @@ -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";
Expand All @@ -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]",
Expand Down Expand Up @@ -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();
});

0 comments on commit edbbb57

Please sign in to comment.