Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mock config to fix issues in concurrent tests
- Loading branch information
Showing
16 changed files
with
222 additions
and
160 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
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ coverage/ | |
exoframe-linux | ||
exoframe-macos | ||
exoframe-win.exe | ||
.idea/ | ||
.idea/ |
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,49 @@ | ||
/* eslint-env jest */ | ||
// mock config module | ||
const cfg = jest.genMockFromModule('../../src/config/index.js'); | ||
|
||
// test config | ||
const testConfig = { | ||
endpoint: 'http://localhost:8080', | ||
endpoints: [ | ||
{ | ||
endpoint: 'http://test.endpoint', | ||
user: null, | ||
token: null, | ||
}, | ||
], | ||
token: 'test-token', | ||
user: { | ||
username: 'admin', | ||
}, | ||
}; | ||
|
||
// saved configs for re-use | ||
const savedConfigs = {}; | ||
|
||
// mock config | ||
let mockConfig = Object.assign({}, testConfig); | ||
|
||
cfg.__save = key => { | ||
savedConfigs[key] = Object.assign({}, mockConfig); | ||
}; | ||
cfg.__restore = key => { | ||
mockConfig = Object.assign({}, savedConfigs[key]); | ||
}; | ||
cfg.updateConfig = newCfg => { | ||
mockConfig = Object.assign(mockConfig, newCfg); | ||
}; | ||
cfg.isLoggedIn = () => { | ||
if (!mockConfig.user || !mockConfig.user.username) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
cfg.logout = newCfg => { | ||
delete newCfg.user; | ||
delete newCfg.token; | ||
mockConfig = Object.assign({}, newCfg); | ||
}; | ||
cfg.userConfig = mockConfig; | ||
|
||
module.exports = cfg; |
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.