Skip to content

Instantly share code, notes, and snippets.

@benoitguigal
Last active June 28, 2021 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitguigal/0e5418ee0de441fbdc41683631059406 to your computer and use it in GitHub Desktop.
Save benoitguigal/0e5418ee0de441fbdc41683631059406 to your computer and use it in GitHub Desktop.
automatic workflow
import { userWithCompanyFactory } from "../../../__tests__/factories";
import makeClient from "../../../__tests__/testClient";
import fs from "fs";
const workflow = {
title: "Acheminement direct du producteur à l'installation de traitement",
actors: ["producer"],
steps: [
{
description: "Le producteur de déchet crée le bordereau",
mutation: "createForm", // name of the mutation
path: "/path/to/createForm.graphql",
variables: { producer } => ({
emitter: {
company: {
siret: producer.siret
}
}
}),
expected: { status: "DRAFT" },
actor: "producer",
setContext: (ctx, data) => ({ ...ctx, id: data.id })
},
{
description: "Le producteur de déchet scelle le bordereau",
mutation: "markAsSealed",
path: "/path/to/markAsSealed.graphql",
variables: { id } => ({ id }),
expected: { status: "SEALED" },
actor: "producer"
}
]
};
test(workflow.title, async () => {
// init a context that can be passed from one step to the other
let context = {};
// create different companies used in this workflow
for (const actor of workflow.actors) {
const { user, company } = await userWithCompanyFactory("MEMBER");
context = { ...context, [actor]: { ...company, user } };
}
// run the steps one by one
for (const step of workflow.steps) {
const { mutate } = makeClient(context[step.actor].user);
const { data } = await mutate(fs.readFileSync(step.path, "utf-8"), {
variables: step.variables(context)
});
context = step.setContext(context, data[step.mutation]);
expect(data[step.mutation]).toEqual(expect.objectContaining(step.expected));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment