-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
- Loading branch information
Showing
26 changed files
with
1,446 additions
and
468 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,35 @@ | ||
name: code coverage | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
|
||
jobs: | ||
run-codecov: | ||
if: github.event.pull_request.draft == false | ||
runs-on: macos-latest | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup the serve environment | ||
shell: bash -l {0} | ||
run: | | ||
bash setup/setup_serve.sh | ||
- name: Run Jest tests | ||
shell: bash -l {0} | ||
run: | | ||
source setup/activate_serve.sh | ||
npx jest | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
files: ./coverage/coverage-final.json | ||
flags: unit | ||
fail_ci_if_error: ${{ github.repository == 'e-mission/e-mission-phone' }} | ||
|
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 |
---|---|---|
|
@@ -7,5 +7,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: npx prettier --check www | ||
- run: npx [email protected] --check www | ||
|
||
|
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
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
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
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,134 @@ | ||
import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
import { mockAlert, mockLogger } from '../__mocks__/globalMocks'; | ||
import { getConfig, initByUser } from '../js/config/dynamicConfig'; | ||
|
||
import initializedI18next from '../js/i18nextInit'; | ||
import { storageClear } from '../js/plugin/storage'; | ||
window['i18next'] = initializedI18next; | ||
|
||
mockLogger(); | ||
mockAlert(); | ||
mockBEMUserCache(); | ||
|
||
beforeEach(() => { | ||
// clear all storage and the config document | ||
storageClear({ local: true, native: true }); | ||
window['cordova'].plugins.BEMUserCache.putRWDocument('config/app_ui_config', {}); | ||
}); | ||
|
||
const nrelCommuteConfig = { | ||
version: 1, | ||
server: { | ||
connectUrl: 'https://nrel-commute-openpath.nrel.gov/api/', | ||
aggregate_call_auth: 'user_only', | ||
}, | ||
// ... | ||
}; | ||
|
||
const denverCasrConfig = { | ||
version: 1, | ||
server: { | ||
connectUrl: 'https://denver-casr-openpath.nrel.gov/api/', | ||
aggregate_call_auth: 'user_only', | ||
}, | ||
opcode: { | ||
autogen: true, | ||
subgroups: [ | ||
'test', | ||
'qualified-cargo', | ||
'qualified-regular', | ||
'standard-cargo', | ||
'standard-regular', | ||
], | ||
}, | ||
// ... | ||
}; | ||
|
||
global.fetch = (url: string) => { | ||
return new Promise((rs, rj) => { | ||
if (url.includes('nrel-commute.nrel-op.json')) { | ||
rs({ | ||
ok: true, | ||
json: () => new Promise((rs, rj) => rs(nrelCommuteConfig)), | ||
}); | ||
} else if (url.includes('denver-casr.nrel-op.json')) { | ||
rs({ | ||
ok: true, | ||
json: () => new Promise((rs, rj) => rs(denverCasrConfig)), | ||
}); | ||
} else { | ||
rj(new Error('404 while fetching ' + url)); | ||
} | ||
}) as any; | ||
}; | ||
|
||
describe('dynamicConfig', () => { | ||
const fakeStudyName = 'gotham-city-transit'; | ||
const validStudyNrelCommute = 'nrel-commute'; | ||
const validStudyDenverCasr = 'denver-casr'; | ||
|
||
describe('getConfig', () => { | ||
it('should resolve with null since no config is set yet', async () => { | ||
await expect(getConfig()).resolves.toBeNull(); | ||
}); | ||
it('should resolve with a valid config once initByUser is called for an nrel-commute token', async () => { | ||
const validToken = `nrelop_${validStudyNrelCommute}_user1`; | ||
await initByUser({ token: validToken }); | ||
const config = await getConfig(); | ||
expect(config.server.connectUrl).toBe('https://nrel-commute-openpath.nrel.gov/api/'); | ||
expect(config.joined).toEqual({ | ||
opcode: validToken, | ||
study_name: validStudyNrelCommute, | ||
subgroup: undefined, | ||
}); | ||
}); | ||
|
||
it('should resolve with a valid config once initByUser is called for a denver-casr token', async () => { | ||
const validToken = `nrelop_${validStudyDenverCasr}_test_user1`; | ||
await initByUser({ token: validToken }); | ||
const config = await getConfig(); | ||
expect(config.server.connectUrl).toBe('https://denver-casr-openpath.nrel.gov/api/'); | ||
expect(config.joined).toEqual({ | ||
opcode: validToken, | ||
study_name: validStudyDenverCasr, | ||
subgroup: 'test', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('initByUser', () => { | ||
// fake study (gotham-city-transit) | ||
it('should error if the study is nonexistent', async () => { | ||
const fakeBatmanToken = `nrelop_${fakeStudyName}_batman`; | ||
await expect(initByUser({ token: fakeBatmanToken })).rejects.toThrow(); | ||
}); | ||
|
||
// real study without subgroups (nrel-commute) | ||
it('should error if the study exists but the token is invalid format', async () => { | ||
const badToken1 = validStudyNrelCommute; // doesn't start with nrelop_ | ||
await expect(initByUser({ token: badToken1 })).rejects.toThrow(); | ||
const badToken2 = `nrelop_${validStudyNrelCommute}`; // doesn't have enough _ | ||
await expect(initByUser({ token: badToken2 })).rejects.toThrow(); | ||
const badToken3 = `nrelop_${validStudyNrelCommute}_`; // doesn't have user code after last _ | ||
await expect(initByUser({ token: badToken3 })).rejects.toThrow(); | ||
}); | ||
it('should return true after successfully storing the config for a valid token', async () => { | ||
const validToken = `nrelop_${validStudyNrelCommute}_user2`; | ||
await expect(initByUser({ token: validToken })).resolves.toBe(true); | ||
}); | ||
|
||
// real study with subgroups (denver-casr) | ||
it('should error if the study uses subgroups but the token has no subgroup', async () => { | ||
const tokenWithoutSubgroup = `nrelop_${validStudyDenverCasr}_user2`; | ||
await expect(initByUser({ token: tokenWithoutSubgroup })).rejects.toThrow(); | ||
}); | ||
it('should error if the study uses subgroups and the token is invalid format', async () => { | ||
const badToken1 = `nrelop_${validStudyDenverCasr}_test_`; // doesn't have user code after last _ | ||
await expect(initByUser({ token: badToken1 })).rejects.toThrow(); | ||
}); | ||
it('should return true after successfully storing the config for a valid token with subgroup', async () => { | ||
const validToken = `nrelop_${validStudyDenverCasr}_test_user2`; | ||
await expect(initByUser({ token: validToken })).resolves.toBe(true); | ||
}); | ||
}); | ||
}); |
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
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.