Skip to content

Commit

Permalink
fix(api-form-builder): improve test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Oct 29, 2021
1 parent 4d692d8 commit 602494f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 75 deletions.
34 changes: 12 additions & 22 deletions packages/api-form-builder/__tests__/forms.test.ts
Expand Up @@ -4,7 +4,7 @@ import csv from "csvtojson";
import useGqlHandler from "./useGqlHandler";
import { fields, formSubmissionDataA, formSubmissionDataB } from "./mocks/form.mocks";

jest.setTimeout(60000);
jest.setTimeout(100000);

describe('Form Builder "Form" Test', () => {
const {
Expand Down Expand Up @@ -91,9 +91,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data[0].name === newData.name,
{
name: "list forms after update revision",
wait: 500,
tries: 20
name: "list forms after update revision"
}
);

Expand All @@ -114,9 +112,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data.length > 0,
{
name: "after create form",
wait: 500,
tries: 20
name: "after create form"
}
);

Expand All @@ -131,9 +127,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data[0].id === id3,
{
name: "after create revisions",
wait: 500,
tries: 20
name: "after create revisions"
}
);

Expand All @@ -160,9 +154,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data[0].id === id2,
{
name: "after delete revision 3",
wait: 500,
tries: 20
name: "after delete revision 3"
}
);

Expand Down Expand Up @@ -209,9 +201,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data.length === 0,
{
name: "list after delete form",
wait: 500,
tries: 20
name: "list after delete form"
}
);

Expand All @@ -232,9 +222,7 @@ describe('Form Builder "Form" Test', () => {
() => listForms().then(([data]) => data),
({ data }) => data.formBuilder.listForms.data[0].id === id,
{
name: "list forms after publish revision",
wait: 500,
tries: 20
name: "list forms after publish revision"
}
);

Expand Down Expand Up @@ -305,6 +293,8 @@ describe('Form Builder "Form" Test', () => {

await publishRevision({ revision: id });

await new Promise(res => setTimeout(res, 2000));

// Create form submissions
const [createSubmission1Response] = await createFormSubmission({
revision: id,
Expand All @@ -322,6 +312,8 @@ describe('Form Builder "Form" Test', () => {
}
});

await new Promise(res => setTimeout(res, 2000));

const [createSubmission2Response] = await createFormSubmission({
revision: id,
data: formSubmissionDataB.data,
Expand All @@ -342,9 +334,7 @@ describe('Form Builder "Form" Test', () => {
() => listFormSubmissions({ form: id, sort: "savedOn_ASC" }).then(([data]) => data),
({ data }) => data.formBuilder.listFormSubmissions.data.length === 2,
{
name: "after create submission",
wait: 500,
tries: 200
name: "after create submission"
}
);

Expand Down
43 changes: 0 additions & 43 deletions packages/api-form-builder/__tests__/helpers.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api-form-builder/__tests__/useGqlHandler.ts
Expand Up @@ -38,7 +38,7 @@ import {
EXPORT_FORM_SUBMISSIONS
} from "./graphql/formSubmission";
import { SecurityPermission } from "@webiny/api-security/types";
import { until } from "./helpers";
import { until } from "@webiny/project-utils/testing/helpers/until";
import { createTenancyAndSecurity } from "./tenancySecurity";

export interface UseGqlHandlerParams {
Expand Down
9 changes: 1 addition & 8 deletions packages/cli-plugin-deploy-pulumi/utils/getStackOutput.js
Expand Up @@ -21,14 +21,7 @@ const getOutputJson = ({ folder, env, cwd }) => {

// Let's get the output after the first line break. Everything before is just yarn stuff.
const extractedJSON = stdout.substring(stdout.indexOf("{"));
const values = JSON.parse(extractedJSON);
Object.keys(values).forEach(key => {
if (typeof values[key] === "object") {
values[key].toString = () => JSON.stringify(values[key]);
}
});
cache[folder + env] = values;
return cache[folder + env];
return (cache[folder + env] = JSON.parse(extractedJSON));
} catch (e) {
return null;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-plugin-deploy-pulumi/utils/mapStackOutput.js
Expand Up @@ -15,7 +15,12 @@ module.exports = (output, map) => {
console.log(yellow(`Could not map "${valuePath}" to "${key}" - value missing.`));
return;
}
values[key] = valuePattern.replace(replace, value);

if (typeof value === "object" && value !== null) {
values[key] = valuePattern.replace(replace, JSON.stringify(value));
} else {
values[key] = valuePattern.replace(replace, value);
}
}
});

Expand Down

0 comments on commit 602494f

Please sign in to comment.