Last active
June 28, 2021 09:34
-
-
Save benoitguigal/0e5418ee0de441fbdc41683631059406 to your computer and use it in GitHub Desktop.
automatic workflow
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
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