From 7c7ea5972e0d03778cf54ea077e96a87ffb4b928 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 10:43:25 -0600
Subject: [PATCH 01/26] correct the customApiIntercept `loading` case
`req.reply()` was not returning an empty response, it was returning the
actual response from the server. this led to the "loading" state being
present momentarily before the actual response was returned. we are now
forcing the loading state to remain, as the mock intends.
---
cypress/support/commands.js | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index dcf2c9a..d2f3d9f 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -23,6 +23,7 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
+
import { scientistApiBaseURL } from './e2e'
// add a command to login that uses a session, so the user will remain logged in throughout the test file vs. needing to log in before each example.
@@ -44,10 +45,10 @@ Cypress.Commands.add('login', (username, password) => {
Cypress.Commands.add('customApiIntercept', ({
action, alias, data, defaultFixture, emptyFixture, error, errorCaseStatusCode, loading, requestURL
}) => {
- cy.intercept(action, scientistApiBaseURL + requestURL, (req) => {
+ cy.intercept(action, `${scientistApiBaseURL}${requestURL}`, (req) => {
switch (true) {
// reply with an empty response: both data and error will be undefined.
- case loading: req.reply()
+ case loading: req.reply({})
break
// error will be defined
@@ -66,4 +67,4 @@ Cypress.Commands.add('customApiIntercept', ({
break
}
}).as(alias || 'customIntercept')
-})
\ No newline at end of file
+})
From f9d4eae97e304ef9bedd9e1ad16295338650238a Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 10:50:35 -0600
Subject: [PATCH 02/26] fix the first home spec
made the cypress config file more dynamic. it also will allow us to
correctly intercept api calls in our `customApiIntercept` command.
update the "featured services list is loading" test check that we in
fact have 3 placeholder items, as the description states.
---
cypress.config.js | 11 ++++++++---
cypress/e2e/home.cy.js | 11 ++++-------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/cypress.config.js b/cypress.config.js
index 529841c..3ff5cbd 100644
--- a/cypress.config.js
+++ b/cypress.config.js
@@ -23,12 +23,17 @@ module.exports = defineConfig({
env: {
TEST_SCIENTIST_USER: 'test@test.com',
TEST_SCIENTIST_PW: '!test1234',
- NEXT_PUBLIC_PROVIDER_NAME: 'acme',
- NEXT_PUBLIC_PROVIDER_ID: '572'
+ NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
+ NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
+ NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
+ // importing the `API_PER_PAGE` variable from the constants file throws
+ // errors since this file doesn't follow ES6 syntax. if the value is
+ // changed in constants, it needs to be updated here too
+ API_PER_PAGE: 2000,
},
reporter: 'junit',
reporterOptions: {
mochaFile: 'cypress/results/results-[hash].xml',
toConsole: true,
},
-});
+})
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index cff47a0..5d97967 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -5,11 +5,10 @@ describe('Viewing Home page', () => {
let featuredServices
beforeEach(() => {
- // Intercept the response from the endpoint to view all requests
cy.customApiIntercept({
action: 'GET',
alias: 'useAllWares',
- requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`,
+ requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
data: featuredServices,
defaultFixture: 'services/wares.json',
emptyFixture: 'services/no-wares.json',
@@ -19,13 +18,11 @@ describe('Viewing Home page', () => {
cy.visit('/')
})
-
context('featured services list is loading', () => {
- before(() => {
- loading = true
- })
+ before(() => loading = true)
+
it('should show 3 placeholder cards loading', () => {
- cy.get('p.placeholder-glow').should('be.visible').then(() => {
+ cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
cy.log('Loading text displays correctly.')
})
})
From 940b731ef061bd95ea77471e1b89c9d71de908b4 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 13:11:06 -0600
Subject: [PATCH 03/26] refactor the home page specs
changed up the specs to fit the flow of the home page. also moving two
specs from the browse page to the home page since that's where the
requests originate from.
---
cypress.config.js | 1 +
cypress/e2e/browse.cy.js | 41 ++---------------
cypress/e2e/home.cy.js | 95 +++++++++++++++++++++++++++-------------
3 files changed, 69 insertions(+), 68 deletions(-)
diff --git a/cypress.config.js b/cypress.config.js
index 3ff5cbd..736d283 100644
--- a/cypress.config.js
+++ b/cypress.config.js
@@ -26,6 +26,7 @@ module.exports = defineConfig({
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
+ CYPRESS_SEARCH_QUERY: 'test',
// importing the `API_PER_PAGE` variable from the constants file throws
// errors since this file doesn't follow ES6 syntax. if the value is
// changed in constants, it needs to be updated here too
diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js
index dd0e64f..aee5320 100644
--- a/cypress/e2e/browse.cy.js
+++ b/cypress/e2e/browse.cy.js
@@ -19,10 +19,10 @@ describe('Browsing', () => {
emptyFixture: 'services/no-wares.json',
},
]
-
+
beforeEach(() => {
// Intercept the responses from the endpoint to view all requests.
- // Even though this is to the same endpoint, the call happens on each page twice,
+ // Even though this is to the same endpoint, the call happens on each page twice,
// once when the page loads with all the wares, and again after any search is performed.
// this makes it necessary to create an intercept for each time the call is made.
intercepts.forEach((intercept) => {
@@ -103,39 +103,4 @@ describe('Browsing', () => {
})
})
})
-
- describe('from the home page', () => {
- beforeEach(() => {
- wares = true
- // Intercept the api call being made on the homepage
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllWares',
- requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`,
- data: wares,
- defaultFixture: 'services/wares.json',
- loading,
- error
- })
- cy.visit('/')
- })
-
- context('a search is completed successfully and', () => {
- it('navigates to "/browse" with a blank query', () => {
- cy.get('button.search-button').click()
- cy.url().should('include', '/browse')
- cy.url().should('not.include', '?')
- cy.get('input.search-bar').should('have.value', '')
- cy.get(".card[data-cy='item-card']").should('be.visible')
- })
-
- it('navigates to "/browse" with a query term', () => {
- cy.get('input.search-bar').type('test')
- cy.get('button.search-button').click()
- cy.url().should('include', '/browse?q=test')
- cy.get('input.search-bar').should('have.value', 'test')
- cy.get(".card[data-cy='item-card']").should('be.visible')
- })
- })
- })
-})
\ No newline at end of file
+})
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 5d97967..3aee830 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -1,4 +1,4 @@
-describe('Viewing Home page', () => {
+describe('Navigating to the home page', () => {
// declare variables that can be used to change how the response is intercepted.
let loading
let error
@@ -18,47 +18,82 @@ describe('Viewing Home page', () => {
cy.visit('/')
})
- context('featured services list is loading', () => {
- before(() => loading = true)
-
- it('should show 3 placeholder cards loading', () => {
- cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
- cy.log('Loading text displays correctly.')
+ describe('renders a search bar', () => {
+ it('with no query', () => {
+ cy.get("form[data-cy='search-bar']").should('exist').then(() => {
+ cy.log('Search bar renders successfully.')
})
})
- })
- context('error while making a request to the api', () => {
- before(() => {
- loading = false
- error = true
+ it('able to navigate to "/browse" with a blank query', () => {
+ cy.get('button.search-button').click()
+ cy.url().should('include', '/browse')
+ cy.url().should('not.include', '?')
+ cy.get('input.search-bar').should('have.value', '')
+ cy.get(".card[data-cy='item-card']").should('be.visible')
})
- it('should show an error message.', () => {
- cy.get("div[role='alert']").should('be.visible').then(() => {
- cy.log('Successfully hits an error.')
- })
+
+ it('able to navigate to "/browse" with a valid query term', () => {
+ cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
+ cy.get('button.search-button').click()
+ cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
+ cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY'))
+ cy.get(".card[data-cy='item-card']").should('be.visible')
+ })
+
+ it('able to navigate to "/browse" with an invalid query term', () => {
+ cy.get('input.search-bar').type('test')
+ cy.get('button.search-button').click()
+ cy.url().should('include', '/browse?q=test')
+ cy.get('input.search-bar').should('have.value', 'test')
+ cy.get(".card[data-cy='item-card']").should('be.visible')
})
})
- context('home page components are loading successfully, &', () => {
- before(() => {
- featuredServices = true
- error = false
+ describe('renders a text box', () => {
+ it('showing the about text.', () => {
+ cy.get("section[data-cy='about-us-section']").should('exist').then(() => {
+ cy.log('Abouttext renders successfully.')
+ })
})
- it('should show the search bar.', () => {
- cy.get("form[data-cy='search-bar']").should('exist').then(() => {
- cy.log('Search bar renders successfully.')
+ })
+
+ describe('makes a call to the api', () => {
+ context('which when returns an error', () => {
+ before(() => {
+ loading = false
+ error = true
+ })
+
+ it('shows an error message', () => {
+ // why would we get an error?
+ cy.get("div[role='alert']").should('be.visible').then(() => {
+ cy.log('Successfully hits an error.')
+ })
})
})
- it('should show the about text.', () => {
- cy.get("section[data-cy='about-us-section']").should('exist').then(() => {
- cy.log('Abouttext renders successfully.')
+
+ context('which when returns no error or data', () => {
+ before(() => loading = true)
+
+ it('shows 3 placeholder cards loading', () => {
+ cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
+ cy.log('Loading text displays correctly.')
+ })
})
})
- it('should show the featured services cards.', () => {
- cy.get("div[data-cy='item-group']").should('exist').then(() => {
- cy.log('Status bar renders successfully.')
+
+ context('which when returns data', () => {
+ before(() => {
+ featuredServices = true
+ error = false
+ })
+
+ it('shows the featured services cards', () => {
+ cy.get("div[data-cy='item-group']").should('exist').then(() => {
+ cy.log('Status bar renders successfully.')
+ })
})
})
})
-})
\ No newline at end of file
+})
From 41119301e6bc0c295018d763fad87063e61e31da Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 15:21:14 -0600
Subject: [PATCH 04/26] correctly testing for a search with no query
---
cypress/e2e/home.cy.js | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 3aee830..dc41443 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -3,6 +3,8 @@ describe('Navigating to the home page', () => {
let loading
let error
let featuredServices
+ let requestURL
+ let data
beforeEach(() => {
cy.customApiIntercept({
@@ -25,7 +27,23 @@ describe('Navigating to the home page', () => {
})
})
- it('able to navigate to "/browse" with a blank query', () => {
+ context('able to navigate to "/browse"', () => {
+ const testSetup = ({ data, requestURL }) => {
+ cy.customApiIntercept({
+ action: 'GET',
+ alias: 'useFilteredWares',
+ requestURL,
+ data,
+ defaultFixture: 'services/wares.json',
+ })
+ }
+
+ it('with a blank query', () => {
+ testSetup({
+ requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=`,
+ data: true
+ })
+
cy.get('button.search-button').click()
cy.url().should('include', '/browse')
cy.url().should('not.include', '?')
From 733458a951da38ff520034b0bc071051ce48de5a Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 16:00:11 -0600
Subject: [PATCH 05/26] all search bar tests from the home e2e spec pass
---
cypress/e2e/home.cy.js | 43 ++++++++++++-------
cypress/fixtures/services/filtered-wares.json | 22 ++++++++++
2 files changed, 50 insertions(+), 15 deletions(-)
create mode 100644 cypress/fixtures/services/filtered-wares.json
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index dc41443..0ac61ca 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -1,22 +1,21 @@
describe('Navigating to the home page', () => {
// declare variables that can be used to change how the response is intercepted.
- let loading
let error
let featuredServices
- let requestURL
- let data
+ let loading
beforeEach(() => {
cy.customApiIntercept({
action: 'GET',
alias: 'useAllWares',
- requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
data: featuredServices,
defaultFixture: 'services/wares.json',
emptyFixture: 'services/no-wares.json',
+ error,
loading,
- error
+ requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
})
+
cy.visit('/')
})
@@ -28,20 +27,22 @@ describe('Navigating to the home page', () => {
})
context('able to navigate to "/browse"', () => {
- const testSetup = ({ data, requestURL }) => {
+ const testSetup = ({ data, defaultFixture, requestURL }) => {
cy.customApiIntercept({
action: 'GET',
alias: 'useFilteredWares',
- requestURL,
data,
- defaultFixture: 'services/wares.json',
+ defaultFixture,
+ emptyFixture: 'services/no-wares.json',
+ requestURL,
})
}
it('with a blank query', () => {
testSetup({
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=`,
- data: true
+ data: true,
+ defaultFixture: 'services/wares.json',
})
cy.get('button.search-button').click()
@@ -51,7 +52,13 @@ describe('Navigating to the home page', () => {
cy.get(".card[data-cy='item-card']").should('be.visible')
})
- it('able to navigate to "/browse" with a valid query term', () => {
+ it('with a valid query term', () => {
+ testSetup({
+ requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`,
+ data: true,
+ defaultFixture: 'services/filtered-wares.json',
+ })
+
cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
cy.get('button.search-button').click()
cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
@@ -59,12 +66,18 @@ describe('Navigating to the home page', () => {
cy.get(".card[data-cy='item-card']").should('be.visible')
})
- it('able to navigate to "/browse" with an invalid query term', () => {
- cy.get('input.search-bar').type('test')
+ it('with an invalid query term', () => {
+ const invalidQuery = 'asdfghjk'
+ testSetup({
+ requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${invalidQuery}`,
+ })
+
+ cy.get('input.search-bar').type(invalidQuery)
cy.get('button.search-button').click()
- cy.url().should('include', '/browse?q=test')
- cy.get('input.search-bar').should('have.value', 'test')
- cy.get(".card[data-cy='item-card']").should('be.visible')
+ cy.url().should('include', `/browse?q=${invalidQuery}`)
+ cy.get('input.search-bar').should('have.value', invalidQuery)
+ cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`)
+ })
})
})
diff --git a/cypress/fixtures/services/filtered-wares.json b/cypress/fixtures/services/filtered-wares.json
new file mode 100644
index 0000000..4ac4391
--- /dev/null
+++ b/cypress/fixtures/services/filtered-wares.json
@@ -0,0 +1,22 @@
+{
+ "ware_refs": [
+ {
+ "id": 3456,
+ "slug": "test-ware",
+ "name": "Test Ware",
+ "snippet": "Here is a test ware snippet.",
+ "urls": {
+ "promo_image": "https://y.yarn.co/193fa4ae-a245-4f7a-ac9d-64bbebb18c8d_screenshot.jpg"
+ }
+ },
+ {
+ "id": 4567,
+ "slug": "another-test-ware",
+ "name": "Another Test Ware",
+ "snippet": "Another test snippet.",
+ "urls": {
+ "promo_image": "https://cdn.drawception.com/images/panels/2017/7-2/jtqKRKSpyj-6.png"
+ }
+ }
+ ]
+}
From 531182c43afaf6663d5d9bc8d31ec304859b6f8c Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 8 Feb 2024 17:42:32 -0600
Subject: [PATCH 06/26] formatting
---
cypress/e2e/home.cy.js | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 0ac61ca..519cfad 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -45,12 +45,12 @@ describe('Navigating to the home page', () => {
defaultFixture: 'services/wares.json',
})
- cy.get('button.search-button').click()
- cy.url().should('include', '/browse')
- cy.url().should('not.include', '?')
- cy.get('input.search-bar').should('have.value', '')
- cy.get(".card[data-cy='item-card']").should('be.visible')
- })
+ cy.get('button.search-button').click()
+ cy.url().should('include', '/browse')
+ cy.url().should('not.include', '?')
+ cy.get('input.search-bar').should('have.value', '')
+ cy.get(".card[data-cy='item-card']").should('be.visible')
+ })
it('with a valid query term', () => {
testSetup({
@@ -59,12 +59,12 @@ describe('Navigating to the home page', () => {
defaultFixture: 'services/filtered-wares.json',
})
- cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
- cy.get('button.search-button').click()
- cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
- cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY'))
- cy.get(".card[data-cy='item-card']").should('be.visible')
- })
+ cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
+ cy.get('button.search-button').click()
+ cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`)
+ cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY'))
+ cy.get(".card[data-cy='item-card']").should('be.visible')
+ })
it('with an invalid query term', () => {
const invalidQuery = 'asdfghjk'
From 6cc240a4114e06309267321fe20bca827e10fba6 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Fri, 9 Feb 2024 09:17:03 -0600
Subject: [PATCH 07/26] untrack file in .gitignore
ref: https://stackoverflow.com/a/53431148/8079848
---
.env | 8 --------
1 file changed, 8 deletions(-)
delete mode 100644 .env
diff --git a/.env b/.env
deleted file mode 100644
index 6beb9c3..0000000
--- a/.env
+++ /dev/null
@@ -1,8 +0,0 @@
-# reference https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
-# to learn about the NEXT_PUBLIC prefix
-
-NEXT_PUBLIC_PROVIDER_NAME=beachsidebiotech
-NEXT_PUBLIC_PROVIDER_ID=5159
-NEXT_PUBLIC_SCIENTIST_API_VERSION=v2
-NEXT_PUBLIC_WEBHOOK_URL=http://ss-mailer/webstore
-NEXT_PUBLIC_APP_BASE_URL=https://webstore-staging.vercel.app
From 611356021a088010c45fcd9075f1b77a42d834d1 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Mon, 12 Feb 2024 13:20:01 -0600
Subject: [PATCH 08/26] properly throw errors from fetcher
although we were catching the error in `#fetcher`, we weren't returning
it as an error. it was being returned to the caller as the `data` value.
this means none of our `isError` checks for GET requests were working
properly.
with this commit, we're throwing the error so that we are handling it
on the view correctly.
---
utils/api/base.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/utils/api/base.js b/utils/api/base.js
index b16c0ab..1ae2a44 100644
--- a/utils/api/base.js
+++ b/utils/api/base.js
@@ -11,6 +11,7 @@ export const fetcher = (url, token) => {
.then(res => res.data)
.catch(error => {
Sentry.captureException(error)
+ throw error
})
}
From fd52f079f61d2976c233d0871c490fda5bf4e3bb Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Mon, 12 Feb 2024 13:23:55 -0600
Subject: [PATCH 09/26] correctly accounting for errors on the home page spec
we're testing for an invalid access token now.
the `customApiIntercept` command is also simplified.
---
cypress/e2e/home.cy.js | 21 ++++++++++++--------
cypress/support/commands.js | 38 +++++++++++++------------------------
2 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 519cfad..dd7b79f 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -1,16 +1,14 @@
describe('Navigating to the home page', () => {
// declare variables that can be used to change how the response is intercepted.
+ let data
let error
- let featuredServices
let loading
beforeEach(() => {
cy.customApiIntercept({
action: 'GET',
alias: 'useAllWares',
- data: featuredServices,
- defaultFixture: 'services/wares.json',
- emptyFixture: 'services/no-wares.json',
+ data: 'services/wares.json',
error,
loading,
requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
@@ -90,17 +88,24 @@ describe('Navigating to the home page', () => {
})
describe('makes a call to the api', () => {
- context('which when returns an error', () => {
+ context('which when given an invalid access token', () => {
before(() => {
- loading = false
- error = true
+ data = undefined
+ error = {
+ response: {
+ data: {
+ message: 'No access token provided.',
+ },
+ status: 403,
+ },
+ }
})
it('shows an error message', () => {
- // why would we get an error?
cy.get("div[role='alert']").should('be.visible').then(() => {
cy.log('Successfully hits an error.')
})
+ cy.get("div[role='alert']").contains('No access token provided.')
})
})
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index d2f3d9f..2f7d033 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -30,12 +30,12 @@ import { scientistApiBaseURL } from './e2e'
// source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016
Cypress.Commands.add('login', (username, password) => {
cy.session([username, password], () => {
- cy.intercept("/api/auth/session", { fixture: "session.json" }).as("session");
+ cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session')
- // Set the cookie for cypress.
- // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
- // This cookie also may need to be refreshed intermittently if it expires
- cy.setCookie("next-auth.session-token", Cypress.env('TEST_SESSION_COOKIE'));
+ // Set the cookie for cypress.
+ // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
+ // This cookie also may need to be refreshed intermittently if it expires
+ cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE'))
})
})
@@ -43,28 +43,16 @@ Cypress.Commands.add('login', (username, password) => {
// required params are action, defaultFixture, requestURL
// optional params such as data, loading, and error can be passed depending on the creation of test cases that are related to that specific api call
Cypress.Commands.add('customApiIntercept', ({
- action, alias, data, defaultFixture, emptyFixture, error, errorCaseStatusCode, loading, requestURL
+ action, alias, data, error, loading, requestURL
}) => {
cy.intercept(action, `${scientistApiBaseURL}${requestURL}`, (req) => {
- switch (true) {
- // reply with an empty response: both data and error will be undefined.
- case loading: req.reply({})
- break
-
- // error will be defined
- case error: req.reply({ statusCode: errorCaseStatusCode || 500 })
- break
-
- // reply with a request body- default status code is 200
- case data: req.reply({ fixture: defaultFixture })
- break
-
- // reply with the empty fixture is there is one, and the default as a backup. Allows us to isolate one api call at a time that may potentially respond with empty data.
- case !data: req.reply({ fixture: emptyFixture || defaultFixture })
- break
-
- default: req.reply({ fixture: defaultFixture })
- break
+ const response = {
+ data: { fixture: data },
+ error: { ...error },
+ loading: {},
}
+ console.log({ response })
+
+ return req.reply(response[data || error || loading])
}).as(alias || 'customIntercept')
})
From 808b8383ae151bd4f59b0aefafe5c3f17f07f1ae Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Mon, 12 Feb 2024 15:01:37 -0600
Subject: [PATCH 10/26] all 7 home specs are passing
also further simplified the `customApiIntercept` function.
---
cypress/e2e/home.cy.js | 41 ++++++++++++-------------------------
cypress/support/commands.js | 27 +++++++++++++++---------
2 files changed, 30 insertions(+), 38 deletions(-)
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index dd7b79f..5bc8e0f 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -1,17 +1,14 @@
describe('Navigating to the home page', () => {
// declare variables that can be used to change how the response is intercepted.
- let data
+ let data = 'services/wares.json'
let error
- let loading
beforeEach(() => {
cy.customApiIntercept({
- action: 'GET',
alias: 'useAllWares',
- data: 'services/wares.json',
+ data,
error,
- loading,
- requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}`,
+ requestURL: '/wares.json?per_page=2000',
})
cy.visit('/')
@@ -27,20 +24,17 @@ describe('Navigating to the home page', () => {
context('able to navigate to "/browse"', () => {
const testSetup = ({ data, defaultFixture, requestURL }) => {
cy.customApiIntercept({
- action: 'GET',
alias: 'useFilteredWares',
data,
- defaultFixture,
- emptyFixture: 'services/no-wares.json',
+ error,
requestURL,
})
}
it('with a blank query', () => {
testSetup({
- requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=`,
- data: true,
- defaultFixture: 'services/wares.json',
+ data: 'services/wares.json',
+ requestURL: '/wares.json?per_page=2000&q=',
})
cy.get('button.search-button').click()
@@ -52,9 +46,8 @@ describe('Navigating to the home page', () => {
it('with a valid query term', () => {
testSetup({
- requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`,
- data: true,
- defaultFixture: 'services/filtered-wares.json',
+ data: 'services/filtered-wares.json',
+ requestURL: `/wares.json?per_page=2000&q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`,
})
cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY'))
@@ -67,7 +60,8 @@ describe('Navigating to the home page', () => {
it('with an invalid query term', () => {
const invalidQuery = 'asdfghjk'
testSetup({
- requestURL: `/wares.json?per_page=${Cypress.env('API_PER_PAGE')}&q=${invalidQuery}`,
+ data: 'services/no-wares.json',
+ requestURL: `/wares.json?per_page=2000&q=${invalidQuery}`,
})
cy.get('input.search-bar').type(invalidQuery)
@@ -92,12 +86,10 @@ describe('Navigating to the home page', () => {
before(() => {
data = undefined
error = {
- response: {
- data: {
- message: 'No access token provided.',
- },
- status: 403,
+ body: {
+ message: 'No access token provided.',
},
+ statusCode: 403,
}
})
@@ -110,8 +102,6 @@ describe('Navigating to the home page', () => {
})
context('which when returns no error or data', () => {
- before(() => loading = true)
-
it('shows 3 placeholder cards loading', () => {
cy.get('p.placeholder-glow').should('have.length', 3).then(() => {
cy.log('Loading text displays correctly.')
@@ -120,11 +110,6 @@ describe('Navigating to the home page', () => {
})
context('which when returns data', () => {
- before(() => {
- featuredServices = true
- error = false
- })
-
it('shows the featured services cards', () => {
cy.get("div[data-cy='item-group']").should('exist').then(() => {
cy.log('Status bar renders successfully.')
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index 2f7d033..9ab32fa 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -39,20 +39,27 @@ Cypress.Commands.add('login', (username, password) => {
})
})
-// intercepts requests and creates potential cases for loading, error, data, and empty data
-// required params are action, defaultFixture, requestURL
-// optional params such as data, loading, and error can be passed depending on the creation of test cases that are related to that specific api call
+/**
+ * This command intercepts requests and returns the given stubbed response
+ *
+ * @param {string} alias - the alias to give the intercept (convention is to
+ * use the function name)
+ * @param {string} data - the fixture to return as the response data
+ * @param {object} error - the error object to return as the response error
+ * @param {string} requestURL - the URL to intercept
+ *
+ * @returns {object} - the stubbed response
+ */
Cypress.Commands.add('customApiIntercept', ({
- action, alias, data, error, loading, requestURL
+ alias, data, error, requestURL
}) => {
- cy.intercept(action, `${scientistApiBaseURL}${requestURL}`, (req) => {
+ cy.intercept(`${scientistApiBaseURL}${requestURL}`, (req) => {
const response = {
- data: { fixture: data },
- error: { ...error },
- loading: {},
+ data: data && { fixture: data },
+ error,
}
- console.log({ response })
- return req.reply(response[data || error || loading])
+ // falling back to an empty object mimics the loading state
+ return req.reply(response.data || response.error || {})
}).as(alias || 'customIntercept')
})
From 11f0bc942d35d065321776769dfb9b1b1ab8627a Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 10:28:56 -0600
Subject: [PATCH 11/26] remove now irrelevant code
---
cypress.config.js | 4 ----
1 file changed, 4 deletions(-)
diff --git a/cypress.config.js b/cypress.config.js
index 736d283..93a4fcc 100644
--- a/cypress.config.js
+++ b/cypress.config.js
@@ -27,10 +27,6 @@ module.exports = defineConfig({
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
CYPRESS_SEARCH_QUERY: 'test',
- // importing the `API_PER_PAGE` variable from the constants file throws
- // errors since this file doesn't follow ES6 syntax. if the value is
- // changed in constants, it needs to be updated here too
- API_PER_PAGE: 2000,
},
reporter: 'junit',
reporterOptions: {
From 34a973a2c9d1dbaec5f52108a7bc07e2515a3a53 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 14:39:32 -0600
Subject: [PATCH 12/26] stubbed requests cypress e2e tests are passing
- ref: #362
---
cypress/e2e/requests.cy.js | 131 +++++++++---------
.../fixtures/all-requests/make-a-request.json | 5 +-
2 files changed, 66 insertions(+), 70 deletions(-)
diff --git a/cypress/e2e/requests.cy.js b/cypress/e2e/requests.cy.js
index 9217f4d..64a01e4 100644
--- a/cypress/e2e/requests.cy.js
+++ b/cypress/e2e/requests.cy.js
@@ -1,108 +1,103 @@
-import { scientistApiBaseURL } from '../support/e2e'
-
describe('Viewing all requests', () => {
describe('as a logged out user', () => {
- it('should show an error message.', () => {
- // Visit a protected route in order to allow cypress to set the cookie and mock the login
+ it('shows an error message.', () => {
cy.visit('/requests')
cy.get('div.alert-heading').contains('Unauthorized').then(() => {
cy.log('A logged out user is not able to view requests.')
})
})
})
-
+
describe('as a logged in user', () => {
// declare variables that can be used to change how the response is intercepted.
- let requestList
- let loading
+ let data
let error
beforeEach(() => {
- // Call the custom cypress command to log in
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
- // Intercept the response from the endpoint to view all requests
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllRequests',
- requestURL: `/quote_groups/mine.json`,
- data: requestList,
- defaultFixture: 'all-requests/requests.json',
- emptyFixture: 'all-requests/no-requests.json',
- loading,
- error
- })
- // Intercept the response from the endpoint that gets the default ware ID
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useDefaultWare',
- requestURL: `/wares.json?q=make-a-request`,
- defaultFixture: 'all-requests/make-a-request.json',
- error
- })
- cy.visit('/requests')
})
+ describe('makes a call to the api', () => {
+ beforeEach(() => {
+ cy.customApiIntercept({
+ alias: 'useAllRequests',
+ data,
+ error,
+ requestURL: `/quote_groups/mine.json`,
+ })
- context('request list is loading', () => {
- before(() => {
- loading = true
+ cy.visit('/requests')
})
- it('should show a loading spinner.', () => {
- cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
- cy.log('Loading spinner displays correctly.')
+
+ context('which when given an invalid access token', () => {
+ before(() => {
+ error = {
+ body: {
+ message: 'No access token provided.',
+ },
+ statusCode: 403,
+ }
})
- })
- })
- context('error while making a request to the api', () => {
- before(() => {
- requestList = undefined
- loading = false
- error = true
- })
- it('should show an error message.', () => {
- cy.get("div[role='alert']").should('be.visible').then(() => {
- cy.log('Successfully hits an error.')
+ it('shows an error message.', () => {
+ cy.get("div[role='alert']").should('be.visible').then(() => {
+ cy.log('Successfully hits an error.')
+ })
+ cy.get("div[role='alert']").contains('No access token provided.')
})
})
- })
- describe('request components are loading successfully, &', () => {
- context('the user has requests', () => {
- before(() => {
- requestList = true
- error = false
- })
- it("should show the user's request list.", () => {
- cy.get('article.request-item').should('exist').then(() => {
- cy.log('Successfully viewing request list.')
+ context('which when returns undefined error and data values', () => {
+ it('shows a loading spinner.', () => {
+ cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
+ cy.log('Loading spinner displays correctly.')
})
})
})
- context('the user has 0 requests', () => {
+ describe('which when returns a data object', () => {
before(() => {
- requestList = false
+ data = 'all-requests/requests.json'
+ cy.customApiIntercept({
+ alias: 'useDefaultWare',
+ data: 'all-requests/make-a-request.json',
+ error,
+ requestURL: '/wares.json',
+ })
+ })
+
+ it('renders the "New Request" button for the default service', () => {
+ cy.get("a[data-cy='linked-button']")
+ .should('have.attr', 'href', `/requests/new/make-a-request?id=123`)
+ .and('have.text', 'Initiate a New Request')
+ .then(() => {
+ cy.log('The component displays correctly')
+ })
})
- it("should show a message notifying the user they don't have any requests.", () => {
- cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
- cy.log('Successfully viewing request page with no requests.')
+
+ context('with values', () => {
+ it("shows the user's request list.", () => {
+ cy.get('article.request-item')
+ .should('exist')
+ .and('have.length', 3)
+ .then(() => {
+ cy.log('Successfully viewing request list.')
+ })
})
})
- })
- context('the user can see the component', () => {
- [true, false].forEach((value) => {
+ context('with no values', () => {
before(() => {
- requestList = value
+ data = 'all-requests/no-requests.json'
})
- it(`should show a button that links to the initialize request page for the default ware ${value ? 'with a request list' : 'with 0 requests'}.`, () => {
- cy.get("a[data-cy='linked-button']").should('have.attr', 'href', `/requests/new/make-a-request?id=123`).then(() => {
- cy.log('The component displays correctly')
+
+ it("shows a message notifying the user they don't have any requests.", () => {
+ cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
+ cy.log('Successfully viewing request page with no requests.')
})
})
})
})
})
})
-})
\ No newline at end of file
+})
diff --git a/cypress/fixtures/all-requests/make-a-request.json b/cypress/fixtures/all-requests/make-a-request.json
index 6c36641..3a3c38e 100644
--- a/cypress/fixtures/all-requests/make-a-request.json
+++ b/cypress/fixtures/all-requests/make-a-request.json
@@ -1,7 +1,8 @@
{
"ware_refs": [
{
- "id": 123
+ "id": 123,
+ "slug": "make-a-request"
}
]
-}
\ No newline at end of file
+}
From 0d99f45504073a40b2749999e0d7c294465debd2 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 17:36:43 -0600
Subject: [PATCH 13/26] logged out views for request spec work
---
cypress/e2e/request.cy.js | 79 ++++++++++++++++++++++++++-------------
cypress/support/e2e.js | 47 ++++++++++++++++++++++-
2 files changed, 99 insertions(+), 27 deletions(-)
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index aa83b90..95b4032 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -1,11 +1,10 @@
-import useOneRequestResponseBody from '../fixtures/one-request/request.json'
+import {
+ requestUuid as uuid,
+ requestPageApiCalls as apiCalls,
+} from '../support/e2e'
-describe.skip('Viewing one request', () => {
- // TODO: currently this uses a real request uuid, which would allow it to visit a route that actually existed.
- // since the routes are generated dynamically, we will need to mock the next router in order to generate a route for a fake request w/ mock uuid within the test
- // this test should remain skipped until the above is done since it runs as a regular e2e vs e2e with mocked data
+describe('Viewing one request', () => {
// Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
- let uuid = useOneRequestResponseBody.uuid
describe('as a logged out user', () => {
it('should show an error message.', () => {
@@ -17,30 +16,58 @@ describe.skip('Viewing one request', () => {
})
describe('as a logged in user', () => {
- // declare variables that can be used to change how the response is intercepted.
- let request
- let proposals
- let messages
- let files
- let loading
- let error
-
beforeEach(() => {
- // Call the custom cypress command to log in
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
-
- // Intercept the response from the endpoint to view one request
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useOneRequest',
- requestURL: `/quote_groups/${uuid}.json`,
- data: request,
- dataFixture: 'one-request/request.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
+
+ apiCalls.forEach((item) => {
+ const key = Object.keys(item)[0]
+ cy.customApiIntercept(item[key])
})
+ cy.visit(`/requests/${uuid}`)
+ })
+
+ describe('makes a call to the api', () => {
+ context('which when given an invalid uuid', () => {
+ before(() => {
+ apiCalls['useOneRequest'] = {
+ ...apiCalls['useOneRequest'],
+ error: {
+ body: {
+ message: 'Quote Group Not Found',
+ },
+ statusCode: 404,
+ },
+ requestURL: '/quote_groups/fake-uuid.json'
+ }
+ })
+
+ it('returns an error message', () => {
+ cy.get("div[role='alert']").should('be.visible').then(() => {
+ cy.log('Successfully hits an error.')
+ })
+ cy.get("div[role='alert']").contains('Quote Group Not Found')
+ })
+ })
+
+ context('which when returns undefined error and data values', () => {
+ before(() => {
+ apiCalls.forEach((item) => {
+ const key = Object.keys(item)[0]
+
+ item[key].data = undefined
+ item[key].error = undefined
+ })
+ })
+
+ it('shows a loading spinner.', () => {
+ cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
+ cy.log('Loading spinner displays correctly.')
+ })
+ })
+ })
+
+
cy.customApiIntercept({
action: 'GET',
alias: 'useAllSOWs',
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index b6a7ca5..a16827c 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -16,4 +16,49 @@
// Import commands.js using ES2015 syntax:
import './commands'
-export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
\ No newline at end of file
+export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
+
+let error
+export const requestUuid = '596127b7-2356-45aa-aec4-a4f8608ae755'
+export const requestPageApiCalls = [
+ {
+ 'useOneRequest': {
+ alias: 'useOneRequest',
+ data: 'one-request/request.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}.json`,
+ }
+ },
+ {
+ 'useAllMessages': {
+ alias: 'useAllMessages',
+ data: { messages: [] },
+ error,
+ requestURL: `/quote_groups/${requestUuid}/messages.json`
+ },
+ },
+ {
+ 'useAllSOWs': {
+ alias: 'useAllSOWs',
+ data: [],
+ error,
+ requestURL: `/quote_groups/${requestUuid}/proposals.json`
+ }
+ },
+ {
+ 'useAllFiles': {
+ alias: 'useAllFiles',
+ data: { notes: [] },
+ error,
+ requestURL: `/quote_groups/${requestUuid}/notes.json}`,
+ }
+ },
+ {
+ 'getAllPOs': {
+ alias: 'getAllPOs',
+ data: [],
+ error,
+ requestURL: `/quote_groups/${requestUuid}/quoted_wares/8AE755/purchase_orders.json}`,
+ }
+ }
+]
From 9768a366694695df1c7f196d29d80a8811951cab Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 17:37:15 -0600
Subject: [PATCH 14/26] cleanup
---
cypress/support/commands.js | 25 -------------------------
1 file changed, 25 deletions(-)
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index dcf2c9a..9209922 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -1,28 +1,3 @@
-// ***********************************************
-// This example commands.js shows you how to
-// create various custom commands and overwrite
-// existing commands.
-//
-// For more comprehensive examples of custom
-// commands please read more here:
-// https://on.cypress.io/custom-commands
-// ***********************************************
-//
-//
-// -- This is a parent command --
-// Cypress.Commands.add('login', (email, password) => { ... })
-//
-//
-// -- This is a child command --
-// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
-//
-//
-// -- This is a dual command --
-// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
-//
-//
-// -- This will overwrite an existing command --
-// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import { scientistApiBaseURL } from './e2e'
// add a command to login that uses a session, so the user will remain logged in throughout the test file vs. needing to log in before each example.
From 6fca8ff4bbfeb2f687bd62c66c788ce69df37148 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 17:37:35 -0600
Subject: [PATCH 15/26] wip: still working on this request refactor
---
cypress/e2e/request.cy.js | 114 ++++++++++++++++++--------------------
1 file changed, 54 insertions(+), 60 deletions(-)
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index 95b4032..9a38495 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -67,76 +67,70 @@ describe('Viewing one request', () => {
})
})
+ describe('which when returns request data', () => {
+ it.only('shows the request stats section', () => {
+ cy.get('div.request-stats-card').should('exist').then(() => {
+ cy.log('Request stats section renders successfully.')
+ })
+ })
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllSOWs',
- requestURL: `/quote_groups/${uuid}/proposals.json`,
- data: proposals,
- dataFixture: 'one-request/proposals.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
-
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllMessages',
- requestURL: `/quote_groups/${uuid}/messages.json`,
- data: messages,
- dataFixture: 'one-request/messages.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
-
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllFiles',
- requestURL: `/quote_groups/${uuid}/notes.json`,
- data: files,
- dataFixture: 'one-request/notes.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
- cy.visit(`/requests/${uuid}`)
- })
-
- context('request is loading', () => {
- before(() => {
- loading = true
- })
- it('should show a loading spinner.', () => {
- cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
- cy.log('Loading spinner displays correctly.')
+ it('shows the status bar', () => {
+ cy.get("div[data-cy='status-bar']").should('exist').then(() => {
+ cy.log('Status bar renders successfully.')
+ })
})
- })
- })
- describe('request page components are loading successfully, &', () => {
- context('the request page', () => {
- before(() => {
- loading =
- request = true
- proposals = true
- messages = true
- files = true
+ context('with messages', () => {
+ before(() => {
+ cy.customApiIntercept({
+ action: 'GET',
+ alias: 'useAllMessages',
+ requestURL: `/quote_groups/${uuid}/messages.json`,
+ data: messages,
+ dataFixture: 'one-request/messages.json',
+ emptyDataFixture: 'empty.json',
+ loading,
+ error
+ })
+ })
+
+ it('displays the messages', () => {})
})
- it("should show the request stats section.", () => {
- cy.get('div.request-stats-card').should('exist').then(() => {
- cy.log('Request stats section renders successfully.')
+ context('with documents', () => {
+ before(() => {
+ cy.customApiIntercept({
+ action: 'GET',
+ alias: 'useAllSOWs',
+ requestURL: `/quote_groups/${uuid}/proposals.json`,
+ data: proposals,
+ dataFixture: 'one-request/proposals.json',
+ emptyDataFixture: 'empty.json',
+ loading,
+ error
+ })
})
+
+ it('displays the documents', () => {})
})
- it("should show the status bar.", () => {
- cy.get("div[data-cy='status-bar']").should('exist').then(() => {
- cy.log('Status bar renders successfully.')
+ context('with files', () => {
+ before(() => {
+ cy.customApiIntercept({
+ action: 'GET',
+ alias: 'useAllFiles',
+ requestURL: `/quote_groups/${uuid}/notes.json`,
+ data: files,
+ dataFixture: 'one-request/notes.json',
+ emptyDataFixture: 'empty.json',
+ loading,
+ error
+ })
})
+
+ it('displays the files', () => {})
})
- // TODO: add tests to confirm that messages, files, additional info, document sections all show correctly.
})
})
})
-})
\ No newline at end of file
+})
From 2091b26e6f3c0f76bb4f6c78ac63627c5e8c786b Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 17:40:19 -0600
Subject: [PATCH 16/26] readme updates regarding `TEST_SESSION_COOKIE`
---
README.md | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 20d6925..46c513f 100644
--- a/README.md
+++ b/README.md
@@ -174,14 +174,16 @@ There are 2 types of Cypress tests, e2e & component.
If you are creating an e2e test, it will live in the `cypress/e2e` directory. Component tests will need to be created in a directory called `cypress/component `
#### Cypress ENV Variables
-- the Cypress suite requires an environment variable that should be stored in your `.env.development` and not committed to git.
+- the Cypress suite requires an environment variable that should be stored in your `.env` and not committed to git.
- TEST_SESSION_COOKIE=
- - to get the value for this variable, open your browser to your running app at `localhost:3000`.
+ - to get the value for this variable, open your browser to your running app at `localhost:3000`
+ - sign in
- inspect the page
- - click the "Application" tab
+ - Chrome: click the "Application" tab
+ - Firefox: click the "Storage" tab
- click "Cookies"
- find the value for `next-auth.session-token`
- - copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your .env.development
+ - copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your ``.env``
- do not ever commit this value
- this value will need to be updated whenever the cookie expires, approximately once per month
From 4ad68082f0d9e65c76ae66a4fa4cf74629937025 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Tue, 13 Feb 2024 17:41:11 -0600
Subject: [PATCH 17/26] mistype in the readme
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 46c513f..821b6dd 100644
--- a/README.md
+++ b/README.md
@@ -183,7 +183,7 @@ If you are creating an e2e test, it will live in the `cypress/e2e` directory. Co
- Firefox: click the "Storage" tab
- click "Cookies"
- find the value for `next-auth.session-token`
- - copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your ``.env``
+ - copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your `.env`
- do not ever commit this value
- this value will need to be updated whenever the cookie expires, approximately once per month
From e26afd27fbb569d1f03be7a8195e02e873100b07 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Wed, 14 Feb 2024 10:35:28 -0600
Subject: [PATCH 18/26] request specs for viewing a newly created request pass
---
cypress/e2e/request.cy.js | 4 +--
.../fixtures/one-request/files/default.json | 3 ++
.../one-request/messages/default.json | 3 ++
cypress/fixtures/one-request/pos/default.json | 4 +++
cypress/fixtures/one-request/sows/default.js | 1 +
cypress/support/e2e.js | 30 +++++++++----------
6 files changed, 28 insertions(+), 17 deletions(-)
create mode 100644 cypress/fixtures/one-request/files/default.json
create mode 100644 cypress/fixtures/one-request/messages/default.json
create mode 100644 cypress/fixtures/one-request/pos/default.json
create mode 100644 cypress/fixtures/one-request/sows/default.js
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index 9a38495..eb023e4 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -68,8 +68,8 @@ describe('Viewing one request', () => {
})
describe('which when returns request data', () => {
- it.only('shows the request stats section', () => {
- cy.get('div.request-stats-card').should('exist').then(() => {
+ it('shows the request stats section', () => {
+ cy.get('div.request-stats.card').should('exist').then(() => {
cy.log('Request stats section renders successfully.')
})
})
diff --git a/cypress/fixtures/one-request/files/default.json b/cypress/fixtures/one-request/files/default.json
new file mode 100644
index 0000000..8de43c7
--- /dev/null
+++ b/cypress/fixtures/one-request/files/default.json
@@ -0,0 +1,3 @@
+{
+ "notes": []
+}
diff --git a/cypress/fixtures/one-request/messages/default.json b/cypress/fixtures/one-request/messages/default.json
new file mode 100644
index 0000000..ab71998
--- /dev/null
+++ b/cypress/fixtures/one-request/messages/default.json
@@ -0,0 +1,3 @@
+{
+ "messages": []
+}
diff --git a/cypress/fixtures/one-request/pos/default.json b/cypress/fixtures/one-request/pos/default.json
new file mode 100644
index 0000000..d4adc6a
--- /dev/null
+++ b/cypress/fixtures/one-request/pos/default.json
@@ -0,0 +1,4 @@
+{
+ "total": 0,
+ "purchase_orders": []
+}
diff --git a/cypress/fixtures/one-request/sows/default.js b/cypress/fixtures/one-request/sows/default.js
new file mode 100644
index 0000000..fe51488
--- /dev/null
+++ b/cypress/fixtures/one-request/sows/default.js
@@ -0,0 +1 @@
+[]
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index a16827c..56da25a 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -29,36 +29,36 @@ export const requestPageApiCalls = [
requestURL: `/quote_groups/${requestUuid}.json`,
}
},
- {
- 'useAllMessages': {
- alias: 'useAllMessages',
- data: { messages: [] },
- error,
- requestURL: `/quote_groups/${requestUuid}/messages.json`
- },
- },
{
'useAllSOWs': {
alias: 'useAllSOWs',
- data: [],
+ data: 'one-request/sows/default.js',
error,
requestURL: `/quote_groups/${requestUuid}/proposals.json`
}
},
{
- 'useAllFiles': {
- alias: 'useAllFiles',
- data: { notes: [] },
+ 'useMessages': {
+ alias: 'useMessages',
+ data: 'one-request/messages/default.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}/messages.json`
+ },
+ },
+ {
+ 'useFiles': {
+ alias: 'useFiles',
+ data: 'one-request/files/default.json',
error,
- requestURL: `/quote_groups/${requestUuid}/notes.json}`,
+ requestURL: `/quote_groups/${requestUuid}/notes.json`,
}
},
{
'getAllPOs': {
alias: 'getAllPOs',
- data: [],
+ data: 'one-request/pos/default.json',
error,
- requestURL: `/quote_groups/${requestUuid}/quoted_wares/8AE755/purchase_orders.json}`,
+ requestURL: `/quote_groups/${requestUuid}/quoted_wares/728152/purchase_orders.json`,
}
}
]
From 252cf4e29d026a447083d6a2790dee7fc2492eb0 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Wed, 14 Feb 2024 10:48:21 -0600
Subject: [PATCH 19/26] consistent argument names between request page and api
functions
---
utils/api/requests.js | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/utils/api/requests.js b/utils/api/requests.js
index 057d8bc..3e5355f 100644
--- a/utils/api/requests.js
+++ b/utils/api/requests.js
@@ -42,8 +42,8 @@ export const useOneRequest = (uuid, accessToken) => {
}
}
-export const useAllSOWs = (id, requestIdentifier, accessToken) => {
- const { data, error } = useSWR(accessToken ? [`/quote_groups/${id}/proposals.json`, accessToken] : null)
+export const useAllSOWs = (uuid, requestIdentifier, accessToken) => {
+ const { data, error } = useSWR(accessToken ? [`/quote_groups/${uuid}/proposals.json`, accessToken] : null)
let allSOWs
if (data) {
allSOWs = configureSOWs(data, requestIdentifier)
@@ -84,8 +84,8 @@ export const getAllPOs = async (quotedWareId, uuid, requestIdentifier, accessTok
}
}
-export const useMessages = (requestUuid, accessToken) => {
- const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${requestUuid}/messages.json`, accessToken] : null)
+export const useMessages = (uuid, accessToken) => {
+ const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${uuid}/messages.json`, accessToken] : null)
let messages
if (data) {
messages = configureMessages(data.messages)
@@ -102,11 +102,11 @@ export const useMessages = (requestUuid, accessToken) => {
}
}
-export const useFiles = (id, accessToken) => {
- const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${id}/notes.json`, accessToken] : null)
+export const useFiles = (uuid, accessToken) => {
+ const { data, error, mutate } = useSWR(accessToken ? [`/quote_groups/${uuid}/notes.json`, accessToken] : null)
let files
if (data) {
- files = configureFiles(data.notes)
+ files = configureFiles(data.notes)
}
return {
From 0df8ebc358ee496ad210ca5bbaad68762bcb885b Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Wed, 14 Feb 2024 14:46:29 -0600
Subject: [PATCH 20/26] 8 working request specs!
---
cypress/e2e/request.cy.js | 95 +++++----
cypress/fixtures/one-request/files.json | 23 --
cypress/fixtures/one-request/files/index.json | 32 +++
.../{messages.json => messages/index.json} | 2 +-
cypress/fixtures/one-request/pos/index.json | 37 ++++
cypress/fixtures/one-request/pos/one.json | 199 ++++++++++++++++++
.../{proposals.json => sows/index.json} | 0
cypress/support/e2e.js | 72 +++----
pages/requests/[uuid].js | 4 +-
9 files changed, 356 insertions(+), 108 deletions(-)
delete mode 100644 cypress/fixtures/one-request/files.json
create mode 100644 cypress/fixtures/one-request/files/index.json
rename cypress/fixtures/one-request/{messages.json => messages/index.json} (97%)
create mode 100644 cypress/fixtures/one-request/pos/index.json
create mode 100644 cypress/fixtures/one-request/pos/one.json
rename cypress/fixtures/one-request/{proposals.json => sows/index.json} (100%)
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index eb023e4..b068b25 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -1,11 +1,9 @@
import {
requestUuid as uuid,
- requestPageApiCalls as apiCalls,
+ requestPageApiCalls,
} from '../support/e2e'
describe('Viewing one request', () => {
- // Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
-
describe('as a logged out user', () => {
it('should show an error message.', () => {
cy.visit(`/requests/${uuid}`)
@@ -16,17 +14,22 @@ describe('Viewing one request', () => {
})
describe('as a logged in user', () => {
+ let apiCalls = Object.assign({}, requestPageApiCalls)
+
beforeEach(() => {
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
- apiCalls.forEach((item) => {
- const key = Object.keys(item)[0]
- cy.customApiIntercept(item[key])
+ Object.entries(apiCalls).forEach((item) => {
+ cy.customApiIntercept(item[1])
})
-
cy.visit(`/requests/${uuid}`)
})
+ afterEach(() => {
+ // in order for the tests to not be order dependent, we need to reset the apiCalls object to the original state
+ apiCalls = Object.assign({}, requestPageApiCalls)
+ })
+
describe('makes a call to the api', () => {
context('which when given an invalid uuid', () => {
before(() => {
@@ -52,11 +55,12 @@ describe('Viewing one request', () => {
context('which when returns undefined error and data values', () => {
before(() => {
- apiCalls.forEach((item) => {
- const key = Object.keys(item)[0]
-
- item[key].data = undefined
- item[key].error = undefined
+ Object.entries(apiCalls).forEach(([key, value]) => {
+ apiCalls[key] = {
+ ...value,
+ data: undefined,
+ error: undefined,
+ }
})
})
@@ -82,53 +86,54 @@ describe('Viewing one request', () => {
context('with messages', () => {
before(() => {
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllMessages',
- requestURL: `/quote_groups/${uuid}/messages.json`,
- data: messages,
- dataFixture: 'one-request/messages.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
+ apiCalls['useMessages'] = {
+ ...apiCalls['useMessages'],
+ data: 'one-request/messages/index.json',
+ }
})
- it('displays the messages', () => {})
+ it('displays the messages', () => {
+ cy.get('div.card-body p.card-text')
+ .contains('this is a message from the customer')
+ .should('be.visible')
+ })
})
context('with documents', () => {
before(() => {
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllSOWs',
- requestURL: `/quote_groups/${uuid}/proposals.json`,
- data: proposals,
- dataFixture: 'one-request/proposals.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
+ apiCalls['useAllSOWs'] = {
+ ...apiCalls['useAllSOWs'],
+ data: 'one-request/sows/index.json',
+ }
+ apiCalls['getAllPOs'] = {
+ ...apiCalls['getAllPOs'],
+ data: 'one-request/pos/index.json',
+ }
})
- it('displays the documents', () => {})
+ it('displays the documents', () => {
+ cy.get('div.document').should('have.length', 2)
+ cy.get('div.badge').contains('SOW').should('be.visible')
+ cy.get('div.badge').contains('PO').should('be.visible')
+ })
})
context('with files', () => {
before(() => {
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllFiles',
- requestURL: `/quote_groups/${uuid}/notes.json`,
- data: files,
- dataFixture: 'one-request/notes.json',
- emptyDataFixture: 'empty.json',
- loading,
- error
- })
+ apiCalls['useFiles'] = {
+ ...apiCalls['useFiles'],
+ data: 'one-request/files/index.json',
+ }
})
- it('displays the files', () => {})
+ it('displays the files', () => {
+ cy.get('div.actions-group')
+ .contains('View Files')
+ .click()
+ cy.get('div#document-tabs-tabpane-files')
+ .contains('downtown.jpg')
+ .should('be.visible')
+ })
})
})
})
diff --git a/cypress/fixtures/one-request/files.json b/cypress/fixtures/one-request/files.json
deleted file mode 100644
index 5c8fd4b..0000000
--- a/cypress/fixtures/one-request/files.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
- "notes": [
- {
- "id": 674804,
- "title": null,
- "status": null,
- "body": "hi",
- "created_by": "Summer Cook",
- "created_at": "2023-03-01T22:16:46.167Z",
- "updated_at": "2023-03-01T22:16:46.167Z",
- "attachments": [],
- "user_ref": {
- "first_name": "Summer",
- "last_name": "Cook",
- "organization_name": "Acme",
- "email": "summer@scientist.com",
- "title": "Frontend Dev",
- "company": "",
- "image": "https://avatars.scientist.com/avatars/0d93b3808f701fc3dbde5002a80c2475/S C/xs?time=1677774999"
- }
- }
- ]
-}
diff --git a/cypress/fixtures/one-request/files/index.json b/cypress/fixtures/one-request/files/index.json
new file mode 100644
index 0000000..15a6143
--- /dev/null
+++ b/cypress/fixtures/one-request/files/index.json
@@ -0,0 +1,32 @@
+{
+ "notes": [
+ {
+ "id": 5019371,
+ "title": "New Attachment",
+ "status": "Other File",
+ "body": null,
+ "created_by": "Alisha Evans",
+ "created_at": "2024-02-14T19:40:47.759Z",
+ "updated_at": "2024-02-14T19:40:47.759Z",
+ "attachments": [
+ {
+ "uuid": "fa70a15b-3230-41d5-9913-93ee0bcf2e3e",
+ "filename": "downtown.jpg",
+ "content_type": "image/jpeg",
+ "content_length": 326048,
+ "created_at": "2024-02-14T19:40:47.769Z",
+ "download": "/quote_groups/596127b7-2356-45aa-aec4-a4f8608ae755/attachments/downtown.jpg"
+ }
+ ],
+ "user_ref": {
+ "first_name": "Alisha",
+ "last_name": "Evans",
+ "organization_name": "Acme",
+ "email": "user@example.com",
+ "title": "software engineer",
+ "company": "Triage Pharmaceuticals [DEMO], Scientist.com",
+ "image": "https://avatars.scientist.com/avatars/alpha/user/xs?time=1707939658"
+ }
+ }
+ ]
+}
diff --git a/cypress/fixtures/one-request/messages.json b/cypress/fixtures/one-request/messages/index.json
similarity index 97%
rename from cypress/fixtures/one-request/messages.json
rename to cypress/fixtures/one-request/messages/index.json
index 222addb..0adbe19 100644
--- a/cypress/fixtures/one-request/messages.json
+++ b/cypress/fixtures/one-request/messages/index.json
@@ -54,7 +54,7 @@
"id": 674804,
"title": null,
"status": null,
- "body": "hi",
+ "body": "this is a message from the customer",
"created_by": "Summer Cook",
"created_at": "2023-03-01T22:16:46.167Z",
"updated_at": "2023-03-01T22:16:46.167Z",
diff --git a/cypress/fixtures/one-request/pos/index.json b/cypress/fixtures/one-request/pos/index.json
new file mode 100644
index 0000000..c7efdfa
--- /dev/null
+++ b/cypress/fixtures/one-request/pos/index.json
@@ -0,0 +1,37 @@
+{
+ "total": 1,
+ "purchase_orders": [
+ {
+ "id": 168795,
+ "po_number": "PO595363",
+ "retail_total_price": "1625.0",
+ "retail_subtotal_price": "1425.0",
+ "wholesale_total_price": "1553.75",
+ "wholesale_subtotal_price": "1353.75",
+ "tax_cost": "0.0",
+ "shipping_cost": "200.0",
+ "retail_total_price_currency": "$1,625.00",
+ "retail_subtotal_price_currency": "$1,425.00",
+ "wholesale_total_price_currency": "$1,553.75",
+ "wholesale_subtotal_price_currency": "$1,353.75",
+ "tax_cost_currency": "$0.00",
+ "shipping_cost_currency": "$200.00",
+ "currency": "USD",
+ "currency_unit": "$",
+ "provider_name": "Beachside Biotechnology Services [Demo]",
+ "status": "Work in Progress",
+ "status_description": "(SOW 595363)",
+ "created_at": "2023-12-15T19:45:33.745Z",
+ "updated_at": "2023-12-15T19:45:35.408Z",
+ "type": "PO",
+ "identifier": null,
+ "turn_around_time": {
+ "id": 890642,
+ "min": 604800,
+ "max": 1814400,
+ "display_units": "weeks",
+ "human": "1 - 3 weeks"
+ }
+ }
+ ]
+}
diff --git a/cypress/fixtures/one-request/pos/one.json b/cypress/fixtures/one-request/pos/one.json
new file mode 100644
index 0000000..023bb5a
--- /dev/null
+++ b/cypress/fixtures/one-request/pos/one.json
@@ -0,0 +1,199 @@
+{
+ "purchase_order": {
+ "id": 168795,
+ "po_number": "PO595363",
+ "retail_total_price": "1625.0",
+ "retail_subtotal_price": "1425.0",
+ "wholesale_total_price": "1553.75",
+ "wholesale_subtotal_price": "1353.75",
+ "tax_cost": "0.0",
+ "shipping_cost": "200.0",
+ "retail_total_price_currency": "$1,625.00",
+ "retail_subtotal_price_currency": "$1,425.00",
+ "wholesale_total_price_currency": "$1,553.75",
+ "wholesale_subtotal_price_currency": "$1,353.75",
+ "tax_cost_currency": "$0.00",
+ "shipping_cost_currency": "$200.00",
+ "currency": "USD",
+ "currency_unit": "$",
+ "provider_name": "Beachside Biotechnology Services [Demo]",
+ "status": "Work in Progress",
+ "status_description": "(SOW 595363)",
+ "created_at": "2023-12-15T19:45:33.745Z",
+ "updated_at": "2023-12-15T19:45:35.408Z",
+ "type": "PO",
+ "identifier": null,
+ "turn_around_time": {
+ "id": 890642,
+ "min": 604800,
+ "max": 1814400,
+ "display_units": "weeks",
+ "human": "1 - 3 weeks"
+ },
+ "scientist_identifier": null,
+ "quote_group_name": "65659A: New Request",
+ "quote_group_identifier": "65659A",
+ "quoted_ware_uuids": [
+ "6a96b904-1032-42cb-8083-4afac941f939"
+ ],
+ "quoted_ware_ids": [
+ 168795
+ ],
+ "quoted_ware_uuid": "6a96b904-1032-42cb-8083-4afac941f939",
+ "quoted_ware_id": 168795,
+ "study_objective": "This is a test proposal for the service requested",
+ "payment_terms": "NET 60",
+ "ship_to": {
+ "id": 3512146,
+ "organization_name": "beachsidebiotech",
+ "street": "asdf",
+ "street2": "",
+ "city": "asdf",
+ "state": "asdf",
+ "zipcode": "asdf",
+ "country": "Kazakhstan",
+ "latitude": null,
+ "longitude": null,
+ "name": null,
+ "attention": null,
+ "person_name": "Alisha Evans",
+ "care_of": null,
+ "text": "asdf\nasdf, asdf, asdf"
+ },
+ "ship_from": {
+ "id": 3512148,
+ "organization_name": "Beachside Biotechnology Services",
+ "street": "10",
+ "street2": "",
+ "city": "San Diego",
+ "state": "CA",
+ "zipcode": "91910",
+ "country": "US",
+ "latitude": "32.6385134",
+ "longitude": "-117.0617553",
+ "name": null,
+ "attention": null,
+ "person_name": null,
+ "care_of": null,
+ "text": "10\nSan Diego, CA, 91910\nUnited States"
+ },
+ "line_items": [
+ {
+ "id": 1511411,
+ "retail_unit_price_currency": "$300.00",
+ "retail_unit_price": "300.0",
+ "retail_subtotal_price_currency": "$300.00",
+ "retail_subtotal_price": "300.0",
+ "quantity": "1.0",
+ "currency": "USD",
+ "currency_unit": "$",
+ "name": "Study Design",
+ "subtotal": "$300.00",
+ "unit_price": "$300.00"
+ },
+ {
+ "id": 1511412,
+ "retail_unit_price_currency": "$150.00",
+ "retail_unit_price": "150.0",
+ "retail_subtotal_price_currency": "$600.00",
+ "retail_subtotal_price": "600.0",
+ "quantity": "4.0",
+ "currency": "USD",
+ "currency_unit": "$",
+ "name": "Analysis (3 samples plus control)",
+ "subtotal": "$600.00",
+ "unit_price": "$150.00"
+ },
+ {
+ "id": 1511413,
+ "retail_unit_price_currency": "$500.00",
+ "retail_unit_price": "500.0",
+ "retail_subtotal_price_currency": "$500.00",
+ "retail_subtotal_price": "500.0",
+ "quantity": "1.0",
+ "currency": "USD",
+ "currency_unit": "$",
+ "name": "Report",
+ "subtotal": "$500.00",
+ "unit_price": "$500.00"
+ },
+ {
+ "id": 1511414,
+ "retail_unit_price_currency": "$25.00",
+ "retail_unit_price": "25.0",
+ "retail_subtotal_price_currency": "$25.00",
+ "retail_subtotal_price": "25.0",
+ "quantity": "1.0",
+ "currency": "USD",
+ "currency_unit": "$",
+ "name": "Disposal",
+ "subtotal": "$25.00",
+ "unit_price": "$25.00"
+ }
+ ],
+ "proposal_refs": [
+ {
+ "id": 4594,
+ "type": "SOW",
+ "identifier": "092985",
+ "retail_total_price": "1625.0",
+ "retail_subtotal_price": "1425.0",
+ "wholesale_total_price": "1553.75",
+ "wholesale_subtotal_price": "1353.75",
+ "tax_cost": "0.0",
+ "shipping_cost": "200.0",
+ "retail_total_price_currency": "$1,625.00",
+ "retail_subtotal_price_currency": "$1,425.00",
+ "wholesale_total_price_currency": "$1,553.75",
+ "wholesale_subtotal_price_currency": "$1,353.75",
+ "tax_cost_currency": "$0.00",
+ "shipping_cost_currency": "$200.00",
+ "currency": "USD",
+ "currency_unit": "$",
+ "provider_name": "Beachside Biotechnology Services [Demo]",
+ "status": "Selected for Work",
+ "status_description": "This Proposal has been selected for work",
+ "created_at": "2023-04-14T16:09:35.286Z",
+ "updated_at": "2023-12-15T19:45:33.256Z",
+ "turn_around_time": {
+ "id": 827275,
+ "min": 604800,
+ "max": 1814400,
+ "display_units": "weeks",
+ "human": "1 - 3 weeks"
+ }
+ }
+ ],
+ "proposal_ref": {
+ "id": 158535,
+ "type": "SOW",
+ "identifier": "595363",
+ "retail_total_price": "1625.0",
+ "retail_subtotal_price": "1425.0",
+ "wholesale_total_price": "1553.75",
+ "wholesale_subtotal_price": "1353.75",
+ "tax_cost": "0.0",
+ "shipping_cost": "200.0",
+ "retail_total_price_currency": "$1,625.00",
+ "retail_subtotal_price_currency": "$1,425.00",
+ "wholesale_total_price_currency": "$1,553.75",
+ "wholesale_subtotal_price_currency": "$1,353.75",
+ "tax_cost_currency": "$0.00",
+ "shipping_cost_currency": "$200.00",
+ "currency": "USD",
+ "currency_unit": "$",
+ "provider_name": "Beachside Biotechnology Services [Demo]",
+ "status": "Selected for Work",
+ "status_description": "This Proposal has been selected for work",
+ "created_at": "2023-04-14T16:09:35.286Z",
+ "updated_at": "2023-12-15T19:45:33.256Z",
+ "turn_around_time": {
+ "id": 827275,
+ "min": 604800,
+ "max": 1814400,
+ "display_units": "weeks",
+ "human": "1 - 3 weeks"
+ }
+ }
+ }
+}
diff --git a/cypress/fixtures/one-request/proposals.json b/cypress/fixtures/one-request/sows/index.json
similarity index 100%
rename from cypress/fixtures/one-request/proposals.json
rename to cypress/fixtures/one-request/sows/index.json
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index 56da25a..cc9ffe2 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -19,46 +19,44 @@ import './commands'
export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
let error
+const quotedWareId = 728152
export const requestUuid = '596127b7-2356-45aa-aec4-a4f8608ae755'
-export const requestPageApiCalls = [
- {
- 'useOneRequest': {
- alias: 'useOneRequest',
- data: 'one-request/request.json',
- error,
- requestURL: `/quote_groups/${requestUuid}.json`,
- }
+export const requestPageApiCalls = {
+ 'useOneRequest': {
+ alias: 'useOneRequest',
+ data: 'one-request/request.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}.json`,
},
- {
- 'useAllSOWs': {
- alias: 'useAllSOWs',
- data: 'one-request/sows/default.js',
- error,
- requestURL: `/quote_groups/${requestUuid}/proposals.json`
- }
+ 'useAllSOWs': {
+ alias: 'useAllSOWs',
+ data: 'one-request/sows/default.js',
+ error,
+ requestURL: `/quote_groups/${requestUuid}/proposals.json`
},
- {
- 'useMessages': {
- alias: 'useMessages',
- data: 'one-request/messages/default.json',
- error,
- requestURL: `/quote_groups/${requestUuid}/messages.json`
- },
+ 'useMessages': {
+ alias: 'useMessages',
+ data: 'one-request/messages/default.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}/messages.json`
},
- {
- 'useFiles': {
- alias: 'useFiles',
- data: 'one-request/files/default.json',
- error,
- requestURL: `/quote_groups/${requestUuid}/notes.json`,
- }
+ 'useFiles': {
+ alias: 'useFiles',
+ data: 'one-request/files/default.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}/notes.json`,
},
- {
- 'getAllPOs': {
- alias: 'getAllPOs',
- data: 'one-request/pos/default.json',
- error,
- requestURL: `/quote_groups/${requestUuid}/quoted_wares/728152/purchase_orders.json`,
- }
+ 'getAllPOs': {
+ alias: 'getAllPOs',
+ data: 'one-request/pos/default.json',
+ error,
+ requestURL: `/quote_groups/${requestUuid}/quoted_wares/${quotedWareId}/purchase_orders.json`,
+ },
+ 'getOnePO': {
+ alias: 'getOnePO',
+ data: 'one-request/pos/one.json',
+ error: undefined,
+ requestURL: `/quote_groups/${requestUuid}/quoted_wares/${quotedWareId}/purchase_orders/168795.json`,
}
-]
+}
+
diff --git a/pages/requests/[uuid].js b/pages/requests/[uuid].js
index addbb78..003785e 100644
--- a/pages/requests/[uuid].js
+++ b/pages/requests/[uuid].js
@@ -196,7 +196,7 @@ const Request = ({ session }) => {
{documents.length ? documents.map((document, index) => (
handleAcceptingSOWandCreatingPO(document)}
document={document}
key={`${request.id}-${index}`}
@@ -209,7 +209,7 @@ const Request = ({ session }) => {
text='No documents have been submitted.'
/>
)}
-
+
From 857867d0102fe8af847f5ec9082a47c44ab508d8 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Wed, 14 Feb 2024 15:43:30 -0600
Subject: [PATCH 21/26] cleanup and additional config for specs
---
cypress.config.js | 10 ++++++----
cypress/e2e/request.cy.js | 2 +-
cypress/support/commands.js | 11 ++++++-----
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/cypress.config.js b/cypress.config.js
index 93a4fcc..47d2f0f 100644
--- a/cypress.config.js
+++ b/cypress.config.js
@@ -11,6 +11,7 @@ module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
chromeWebSecurity: false,
+ defaultCommandTimeout: 10000,
setupNodeEvents(on, config) {
config = dotenvFlowPlugin(config)
config.env = {
@@ -21,12 +22,13 @@ module.exports = defineConfig({
},
},
env: {
- TEST_SCIENTIST_USER: 'test@test.com',
- TEST_SCIENTIST_PW: '!test1234',
- NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
+ CYPRESS_SEARCH_QUERY: 'test',
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
+ NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
- CYPRESS_SEARCH_QUERY: 'test',
+ TEST_SCIENTIST_PW: '!test1234',
+ TEST_SCIENTIST_USER: 'test@test.com',
+ TEST_SESSION_COOKIE: process.env.TEST_SESSION_COOKIE,
},
reporter: 'junit',
reporterOptions: {
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index b068b25..a03b39f 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -35,13 +35,13 @@ describe('Viewing one request', () => {
before(() => {
apiCalls['useOneRequest'] = {
...apiCalls['useOneRequest'],
+ data: undefined,
error: {
body: {
message: 'Quote Group Not Found',
},
statusCode: 404,
},
- requestURL: '/quote_groups/fake-uuid.json'
}
})
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index fb8a6d6..c51cae9 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -4,12 +4,13 @@ import { scientistApiBaseURL } from './e2e'
// source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016
Cypress.Commands.add('login', (username, password) => {
cy.session([username, password], () => {
- cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session')
+ cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session')
- // Set the cookie for cypress.
- // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
- // This cookie also may need to be refreshed intermittently if it expires
- cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE'))
+ // Set the cookie for cypress.
+ // It has to be a valid cookie so next-auth can decrypt it and confirm its validity.
+ // This cookie also may need to be refreshed intermittently if it expires
+ // TODO(alishaevn): https://github.com/scientist-softserv/webstore/issues/375
+ cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE'))
})
})
From 35465dd5d998e3b0affb9d98ceef201648ff0c18 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Wed, 14 Feb 2024 15:45:39 -0600
Subject: [PATCH 22/26] lint fixes
---
cypress/e2e/home.cy.js | 2 +-
cypress/e2e/request.cy.js | 4 ++--
cypress/e2e/requests.cy.js | 2 +-
package.json | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 5bc8e0f..1d967bf 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -65,7 +65,7 @@ describe('Navigating to the home page', () => {
})
cy.get('input.search-bar').type(invalidQuery)
- cy.get('button.search-button').click()
+ cy.get('button.search-button').click()
cy.url().should('include', `/browse?q=${invalidQuery}`)
cy.get('input.search-bar').should('have.value', invalidQuery)
cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`)
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index aa83b90..703fce4 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -97,13 +97,13 @@ describe.skip('Viewing one request', () => {
files = true
})
- it("should show the request stats section.", () => {
+ it('should show the request stats section.', () => {
cy.get('div.request-stats-card').should('exist').then(() => {
cy.log('Request stats section renders successfully.')
})
})
- it("should show the status bar.", () => {
+ it('should show the status bar.', () => {
cy.get("div[data-cy='status-bar']").should('exist').then(() => {
cy.log('Status bar renders successfully.')
})
diff --git a/cypress/e2e/requests.cy.js b/cypress/e2e/requests.cy.js
index 64a01e4..4b32557 100644
--- a/cypress/e2e/requests.cy.js
+++ b/cypress/e2e/requests.cy.js
@@ -82,7 +82,7 @@ describe('Viewing all requests', () => {
.and('have.length', 3)
.then(() => {
cy.log('Successfully viewing request list.')
- })
+ })
})
})
diff --git a/package.json b/package.json
index c56ec41..e605779 100644
--- a/package.json
+++ b/package.json
@@ -10,8 +10,8 @@
"cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"",
"cypress:headless:e2e": "start-server-and-test dev http://localhost:3000 \"cypress run --e2e --browser electron\"",
"dev": "next dev",
- "lint": "next lint --dir pages --dir utils",
- "lint:fix": "next lint --dir pages --dir utils --fix",
+ "lint": "next lint --dir pages --dir --dir cypress/e2e utils",
+ "lint:fix": "next lint --dir pages --dir utils --dir cypress/e2e --fix",
"jest": "jest",
"jest-watch": "jest --watch",
"release": "release-it",
From a791cb78d5068b05b7afcf39a4d1fbf3f885bc99 Mon Sep 17 00:00:00 2001
From: Alisha Evans
Date: Thu, 15 Feb 2024 11:27:19 -0600
Subject: [PATCH 23/26] fix the typo in the lint script
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index e605779..3b79040 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"",
"cypress:headless:e2e": "start-server-and-test dev http://localhost:3000 \"cypress run --e2e --browser electron\"",
"dev": "next dev",
- "lint": "next lint --dir pages --dir --dir cypress/e2e utils",
+ "lint": "next lint --dir pages --dir utils --dir cypress/e2e",
"lint:fix": "next lint --dir pages --dir utils --dir cypress/e2e --fix",
"jest": "jest",
"jest-watch": "jest --watch",
From 81f42ae8cb9059454f3ce6a61c476a2e01790d79 Mon Sep 17 00:00:00 2001
From: DaltonMcauliffe
Date: Fri, 23 Feb 2024 15:05:12 -0800
Subject: [PATCH 24/26] Linking to the sign in page on a disabled request form
instead of only displaying text in the notice we converted the text 'please log in' to be a clickable link to log in
issue #383
Co-authored-by: Adrian Carranza
Co-authored-by: Jean Aragon
---
pages/requests/new/[ware].js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/pages/requests/new/[ware].js b/pages/requests/new/[ware].js
index 7604f8b..f214368 100644
--- a/pages/requests/new/[ware].js
+++ b/pages/requests/new/[ware].js
@@ -3,6 +3,7 @@ import { default as BsForm } from 'react-bootstrap/Form'
import Form from '@rjsf/core'
import validator from '@rjsf/validator-ajv8'
import { useRouter } from 'next/router'
+import { signIn } from 'next-auth/react'
import {
AdditionalInfo,
BlankRequestForm,
@@ -22,6 +23,7 @@ import {
sendRequestToVendor,
useInitializeRequest,
useOneWare,
+
} from '../../../utils'
const NewRequest = ({ session }) => {
@@ -266,7 +268,7 @@ const SignInRequired = () => (
To proceed with making a request, signIn(process.env.NEXT_PUBLIC_PROVIDER_NAME)}>please log in to your account.
],
title: 'Sign in required',
variant: 'info'
}}
From f6f5cd38b734fd99fc250953404eadf8b9cf6bdd Mon Sep 17 00:00:00 2001
From: Dalton Mcauliffe
Date: Fri, 23 Feb 2024 15:18:21 -0800
Subject: [PATCH 25/26] Update pages/requests/new/[ware].js
Co-authored-by: Alisha Evans
---
pages/requests/new/[ware].js | 1 -
1 file changed, 1 deletion(-)
diff --git a/pages/requests/new/[ware].js b/pages/requests/new/[ware].js
index f214368..32a02af 100644
--- a/pages/requests/new/[ware].js
+++ b/pages/requests/new/[ware].js
@@ -23,7 +23,6 @@ import {
sendRequestToVendor,
useInitializeRequest,
useOneWare,
-
} from '../../../utils'
const NewRequest = ({ session }) => {
From 0b92f7066df2d29c29e77f7d8a984ec980dc89f5 Mon Sep 17 00:00:00 2001
From: DaltonMcauliffe
Date: Fri, 23 Feb 2024 15:48:15 -0800
Subject: [PATCH 26/26] lint passed local
---
pages/requests/new/[ware].js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pages/requests/new/[ware].js b/pages/requests/new/[ware].js
index 32a02af..812fcb4 100644
--- a/pages/requests/new/[ware].js
+++ b/pages/requests/new/[ware].js
@@ -267,7 +267,8 @@ const SignInRequired = () => (
To proceed with making a request, signIn(process.env.NEXT_PUBLIC_PROVIDER_NAME)}>please log in to your account.],
+ body: [To proceed with making a request, signIn
+ (process.env.NEXT_PUBLIC_PROVIDER_NAME)}>please log in to your account.
],
title: 'Sign in required',
variant: 'info'
}}