Skip to content

Commit

Permalink
Merge pull request #2469 from lmcnulty/checklists-tests-factor-common…
Browse files Browse the repository at this point in the history
…-logic

Factor common checklist test logic
  • Loading branch information
kepae authored Dec 14, 2023
2 parents 7ff2182 + 1deef8f commit ddfd3ec
Showing 1 changed file with 45 additions and 81 deletions.
126 changes: 45 additions & 81 deletions site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ const { gql } = require('@apollo/client');
describe('Checklists App Form', () => {
const url = '/apps/checklists?id=testChecklist';

const defaultChecklist = {
__typename: 'Checklist',
about: '',
id: 'testChecklist',
name: 'Test Checklist',
owner_id: 'a-fake-user-id-that-does-not-exist',
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
};

const usersQuery = {
query: gql`
{
Expand All @@ -19,27 +31,36 @@ describe('Checklists App Form', () => {
timeout: 120000, // mongodb admin api is extremely slow
};

it('Should have read-only access for non-logged-in users', () => {
const withLogin = (callback) => {
cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));

cy.query(usersQuery).then(({ data: { users } }) => {
const user = users.find((user) => user.adminData.email == Cypress.env('e2eUsername'));

callback({ user });
});
};

const interceptFindChecklist = (checklist) => {
cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'findChecklist',
'findChecklist',
{
data: {
checklist: {
__typename: 'Checklist',
about: '',
id: 'testChecklist',
name: 'Test Checklist',
owner_id: 'a-fake-user-id-that-does-not-exist',
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
},
}
{ data: { checklist } }
);
};

const interceptUpsertChecklist = (checklist) => {
cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'upsertChecklist',
'upsertChecklist',
{ data: { checklist } }
);
};

it('Should have read-only access for non-logged-in users', () => {
interceptFindChecklist(defaultChecklist);

cy.visit(url);

Expand All @@ -55,26 +76,7 @@ describe('Checklists App Form', () => {
maybeIt('Should have read-only access for logged-in non-owners', () => {
cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));

cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'findChecklist',
'findChecklist',
{
data: {
checklist: {
__typename: 'Checklist',
about: '',
id: 'testChecklist',
name: 'Test Checklist',
owner_id: 'a-fake-user-id-that-does-not-exist',
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
},
}
);
interceptFindChecklist(defaultChecklist);

cy.visit(url);

Expand All @@ -88,51 +90,13 @@ describe('Checklists App Form', () => {
});

maybeIt('Should allow editing for owner', () => {
cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));

cy.query(usersQuery).then(({ data: { users } }) => {
const user = users.find((user) => user.adminData.email == Cypress.env('e2eUsername'));

cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'findChecklist',
'findChecklist',
{
data: {
checklist: {
__typename: 'Checklist',
about: '',
id: 'testChecklist',
name: 'Test Checklist',
owner_id: user.userId,
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
},
}
);
cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'upsertChecklist',
'upsertChecklist',
{
data: {
checklist: {
__typename: 'Checklist',
about: "It's a system that does something probably.",
id: 'testChecklist',
name: 'Test Checklist',
owner_id: user.userId,
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
},
}
);
withLogin(({ user }) => {
interceptFindChecklist({ ...defaultChecklist, owner_id: user.userId });
interceptUpsertChecklist({
...defaultChecklist,
owner_id: user.userId,
about: "It's a system that does something probably.",
});

cy.visit(url);

Expand Down

0 comments on commit ddfd3ec

Please sign in to comment.