Skip to content

Commit e55d9da

Browse files
committed
Merge branch 'main' into 176-full-color-demo
2 parents 3168788 + 979f51f commit e55d9da

File tree

7 files changed

+209
-134
lines changed

7 files changed

+209
-134
lines changed

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
- [Getting Started](#getting-started)
55
- [Webstore Component Library](#webstore-component-library)
6-
- [Configure token to pull from the github npm repository](#configure-token-to-pull-from-the-github-npm-repository)
76
- [Component Library Dev Mode](#component-library-dev-mode)
87
- [Environment Variables](#environment-variables)
98
- [Authentication](#authentication)
@@ -33,13 +32,7 @@
3332
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. -->
3433

3534
### Webstore Component Library
36-
The webstore requires a [React component library](https://reactjs.org/docs/react-component.html) of view components. That dependency is packaged and released independently and we fetch it from the github repository.
37-
38-
#### Configure token to pull from the github npm repository
39-
Using the published github npm package requires an auth token to pull:
40-
41-
1. Create a classic token on your github account https://github.com/settings/tokens
42-
2. `echo "//npm.pkg.github.com/:_authToken=THE_ABOVE_TOKEN_GOES_HERE" >> ~/.npmrc`
35+
The webstore requires a [React component library](https://reactjs.org/docs/react-component.html) of view components. That dependency is packaged and released independently.
4336

4437
#### Component Library Dev Mode
4538
Using the local github repository requires you to manually clone the component library to your computer, build, and link it:
@@ -150,12 +143,12 @@ If you are creating an e2e test, it will live in the `cypress/e2e` directory. Co
150143
- to get the value for this variable, open your browser to your running app at `localhost:3000`.
151144
- inspect the page
152145
- click the "Application" tab
153-
- click "Cookies"
146+
- click "Cookies"
154147
- find the value for `next-auth.session-token`
155148
- copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your .env.local
156149
- do not ever commit this value
157150
- this value will need to be updated whenever the cookie expires, approximately once per month
158-
151+
159152
## Cutting a New Release
160153
A git tag should exist for every release. We use `release-it` to automate the coordination of package.json and git tag.
161154

cypress/e2e/requests.cy.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { scientistApiBaseURL } from '../support/e2e'
2+
13
describe('Viewing all requests', () => {
24
describe('as a logged out user', () => {
35
it('should show an error message.', () => {
@@ -10,7 +12,6 @@ describe('Viewing all requests', () => {
1012
})
1113

1214
describe('as a logged in user', () => {
13-
let scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
1415
// declare variables that can be used to change how the response is intercepted.
1516
let requestList
1617
let loading
@@ -20,34 +21,23 @@ describe('Viewing all requests', () => {
2021
// Call the custom cypress command to log in
2122
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
2223
// Intercept the response from the endpoint to view all requests
23-
// TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
24-
cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/mine.json`, (req) => {
25-
switch (true) {
26-
// reply with an empty response: both data and error will be undefined.
27-
case loading: req.reply()
28-
break
29-
30-
// error will be defined
31-
case error: req.reply({ statusCode: 500 })
32-
break
33-
34-
case requestList: req.reply({ fixture: 'all-requests/requests.json' })
35-
break
36-
37-
// reply with a request body- default status code is 200
38-
case !requestList: req.reply({ fixture: 'all-requests/no-requests.json' })
39-
break
40-
}
24+
cy.customApiIntercept({
25+
action: 'GET',
26+
alias: 'useAllRequests',
27+
requestURL: `/quote_groups/mine.json`,
28+
data: requestList,
29+
defaultFixture: 'all-requests/requests.json',
30+
emptyFixture: 'all-requests/no-requests.json',
31+
loading,
32+
error
4133
})
4234
// Intercept the response from the endpoint that gets the default ware ID
43-
cy.intercept('GET', `${scientistApiBaseURL}/wares.json?q=make-a-request`, (req) => {
44-
switch (true) {
45-
case error: req.reply({ statusCode: 500 })
46-
break
47-
48-
default: req.reply({ fixture: 'all-requests/make-a-request.json' })
49-
break
50-
}
35+
cy.customApiIntercept({
36+
action: 'GET',
37+
alias: 'useDefaultWare',
38+
requestURL: `/wares.json?q=make-a-request`,
39+
defaultFixture: 'all-requests/make-a-request.json',
40+
error
5141
})
5242
cy.visit('/requests')
5343
})

cypress/support/commands.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//
2424
// -- This will overwrite an existing command --
2525
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26-
26+
import { scientistApiBaseURL } from './e2e'
2727

2828
// 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.
2929
// source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016
@@ -36,4 +36,34 @@ Cypress.Commands.add('login', (username, password) => {
3636
// This cookie also may need to be refreshed intermittently if it expires
3737
cy.setCookie("next-auth.session-token", Cypress.env('TEST_SESSION_COOKIE'));
3838
})
39+
})
40+
41+
// intercepts requests and creates potential cases for loading, error, data, and empty data
42+
// required params are action, defaultFixture, requestURL
43+
// 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
44+
Cypress.Commands.add('customApiIntercept', ({
45+
action, alias, data, defaultFixture, emptyFixture, error, errorCaseStatusCode, loading, requestURL
46+
}) => {
47+
cy.intercept(action, scientistApiBaseURL + requestURL, (req) => {
48+
switch (true) {
49+
// reply with an empty response: both data and error will be undefined.
50+
case loading: req.reply()
51+
break
52+
53+
// error will be defined
54+
case error: req.reply({ statusCode: errorCaseStatusCode || 500 })
55+
break
56+
57+
// reply with a request body- default status code is 200
58+
case data: req.reply({ fixture: defaultFixture })
59+
break
60+
61+
// 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.
62+
case !data: req.reply({ fixture: emptyFixture || defaultFixture })
63+
break
64+
65+
default: req.reply({ fixture: defaultFixture })
66+
break
67+
}
68+
}).as(alias || 'customIntercept')
3969
})

cypress/support/e2e.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
// Import commands.js using ES2015 syntax:
1717
import './commands'
1818

19-
// Alternatively you can use CommonJS syntax:
20-
// require('./commands')
19+
export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@rjsf/core": "^5.0.0-beta.17",
1919
"@rjsf/utils": "^5.0.0-beta.17",
2020
"@rjsf/validator-ajv8": "^5.0.1",
21-
"@scientist-softserv/webstore-component-library": "^0.1.14",
21+
"@scientist-softserv/webstore-component-library": "^0.1.15",
2222
"axios": "^1.1.3",
2323
"bootstrap": "^5.2.3",
2424
"next": "12.3.1",

0 commit comments

Comments
 (0)