Skip to content

Commit

Permalink
Merge pull request #2333 from lmcnulty/checklisting-add-authentication
Browse files Browse the repository at this point in the history
Checklisting – add authentication
  • Loading branch information
kepae authored Oct 19, 2023
2 parents 2bd94b9 + 4308534 commit f262f0d
Show file tree
Hide file tree
Showing 11 changed files with 562 additions and 215 deletions.
148 changes: 148 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { maybeIt } from '../../../support/utils';
const { gql } = require('@apollo/client');

describe('Checklists App Form', () => {
const url = '/apps/checklists?id=testChecklist';

const usersQuery = {
query: gql`
{
users {
userId
roles
adminData {
email
}
}
}
`,
timeout: 60000, // mongodb admin api is extremely slow
};

it('Should have read-only access for non-logged-in users', () => {
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: [],
},
},
}
);

cy.visit(url);

cy.wait(['@findChecklist']);

cy.waitForStableDOM();

cy.get('[data-cy="checklist-form"] textarea:not([disabled])').should('not.exist');

cy.get('[data-cy="checklist-form"] input:not([disabled]):not([readonly])').should('not.exist');
});

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: [],
},
},
}
);

cy.visit(url);

cy.wait(['@findChecklist']);

cy.waitForStableDOM();

cy.get('[data-cy="checklist-form"] textarea:not([disabled])').should('not.exist');

cy.get('[data-cy="checklist-form"] input:not([disabled]):not([readonly])').should('not.exist');
});

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: [],
},
},
}
);

cy.visit(url);

cy.wait(['@findChecklist']);

cy.waitForStableDOM();

cy.get('[data-cy="about"]').type("It's a system that does something probably.");

cy.wait(['@upsertChecklist']);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { maybeIt } from '../../../support/utils';

const { gql } = require('@apollo/client');

describe('Checklists App Index', () => {
const url = '/apps/checklists';

const newChecklistButtonQuery = '#new-checklist-button';

const usersQuery = {
query: gql`
{
users {
userId
roles
adminData {
email
}
}
}
`,
timeout: 60000, // mongodb admin api is extremely slow
};

it('Should not display New Checklist button as non-logged-in user', () => {
cy.visit(url);

cy.get(newChecklistButtonQuery).should('not.exist');
});

maybeIt('Should display New Checklist button as logged-in user', () => {
cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));

cy.visit(url);

cy.get(newChecklistButtonQuery).should('exist');
});

maybeIt('Should show delete buttons only for owned checklists', () => {
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 == 'findChecklists',
'findChecklists',
{
data: {
checklists: [
{
about: '',
id: 'fakeChecklist1',
name: 'My Checklist',
owner_id: user.userId,
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
{
about: '',
id: 'fakeChecklist2',
name: "Somebody Else's Checklist",
owner_id: 'aFakeUserId',
risks: [],
tags_goals: [],
tags_methods: [],
tags_other: [],
},
],
},
}
);

cy.visit(url);

cy.wait(['@findChecklists']);

cy.waitForStableDOM();

cy.get('[data-cy="checklist-card"]:first-child button').contains('Delete').should('exist');

cy.get('[data-cy="checklist-card"]:last-child button').contains('Delete').should('not.exist');
});
});
});
Loading

0 comments on commit f262f0d

Please sign in to comment.