-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2333 from lmcnulty/checklisting-add-authentication
Checklisting – add authentication
- Loading branch information
Showing
11 changed files
with
562 additions
and
215 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
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
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 { | ||
} | ||
} | ||
} | ||
`, | ||
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']); | ||
}); | ||
}); | ||
}); |
88 changes: 88 additions & 0 deletions
88
site/gatsby-site/cypress/e2e/integration/apps/checklistsIndex.cy.js
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
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 { | ||
} | ||
} | ||
} | ||
`, | ||
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'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.