-
Notifications
You must be signed in to change notification settings - Fork 2
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 #435 from DSACMS/cb3c/install-vitest-javascript-un…
…it-testing FFS-2455: Install vitest javascript unit testing and refactor JS code that calls Internal API's
- Loading branch information
Showing
19 changed files
with
1,839 additions
and
108 deletions.
There are no files selected for viewing
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,17 @@ | ||
name: Vitest Javascript Unit Tests | ||
|
||
on: | ||
pull_request: | ||
paths: ['app/**'] | ||
|
||
jobs: | ||
vitest: | ||
name: Vitest | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Ruby & Javascript | ||
uses: ./.github/actions/setup-languages | ||
- name: Run Vitest | ||
working-directory: app | ||
run: npm run test |
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 |
---|---|---|
|
@@ -61,4 +61,7 @@ terraform.tfstate.backup | |
/config/credentials/production.key | ||
|
||
#Profiler | ||
/profiler | ||
/profiler | ||
|
||
# Vitest | ||
.vitest |
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
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,19 @@ | ||
import { fetchInternal } from './fetchInternal'; | ||
|
||
export const PINWHEEL_USER_ACTION = '/api/pinwheel/user_action'; | ||
export const PINWHEEL_TOKENS_GENERATE = '/api/pinwheel/tokens'; | ||
|
||
export const trackUserAction = (eventName, attributes, scope="pinwheel") => { | ||
return fetchInternal(PINWHEEL_USER_ACTION, { | ||
method: 'post', | ||
body: JSON.stringify({ [scope]: { event_name: eventName, attributes } }), | ||
}) | ||
}; | ||
|
||
export const fetchToken = (response_type, id, locale) => { | ||
return fetchInternal(PINWHEEL_TOKENS_GENERATE, { | ||
method: 'post', | ||
body: JSON.stringify({ response_type, id, locale }), | ||
}) | ||
}; | ||
|
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,20 @@ | ||
import CSRF from './csrf'; | ||
|
||
|
||
export const fetchInternal = (uri, params) => { | ||
const defaultHeaders = { | ||
'X-CSRF-Token': CSRF.token, | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
return fetch(uri, addHeadersToParams(defaultHeaders, params)) | ||
.then(response => response.json()); | ||
}; | ||
const addHeadersToParams = (defaultHeaders, params) => { | ||
const requestedHeaders = params.headers; | ||
params.headers = requestedHeaders ? | ||
Object.assign({}, defaultHeaders, requestedHeaders) : | ||
defaultHeaders; | ||
|
||
return params; | ||
}; |
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,20 @@ | ||
import CSRF from './csrf'; | ||
|
||
|
||
export const fetchInternalAPIService = (uri, params) => { | ||
const defaultHeaders = { | ||
'X-CSRF-Token': CSRF.token, | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
return fetch(uri, _addHeadersToParams(defaultHeaders, params)) | ||
.then(response => response.json()); | ||
}; | ||
const _addHeadersToParams = (defaultHeaders, params) => { | ||
const requestedHeaders = params.headers; | ||
params.headers = requestedHeaders ? | ||
Object.assign({}, defaultHeaders, requestedHeaders) : | ||
defaultHeaders; | ||
|
||
return params; | ||
}; |
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
Oops, something went wrong.