-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 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,66 @@ | ||
const { removeClients } = require('../../../commands/remove/client'); | ||
const { addClient } = require('../../../commands/add/client'); | ||
const importedModule = require('../../../commands/add/ignore'); | ||
const { getConfig, setConfig } = require('../../../lib/config'); | ||
|
||
const { addIgnores } = importedModule; | ||
const { | ||
validFamily, | ||
validTypeSource, | ||
validSourceName, | ||
validUrl, | ||
validSourceClient, | ||
} = require('../../__mock__/constants'); | ||
|
||
describe('weaver add ignore command tests', () => { | ||
test('Base behavior', () => { | ||
expect(importedModule).not.toBe(undefined); | ||
}); | ||
test('Methods coverage', () => { | ||
const coveredMethods = [ | ||
'addIgnores', | ||
'commandName', | ||
'commandDesc', | ||
'commandSpec', | ||
'commandHandler', | ||
]; | ||
const filter = (k) => coveredMethods.indexOf(k) < 0; | ||
const uncoveredMethods = Object.keys(importedModule).filter(filter); | ||
expect(uncoveredMethods.length).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('addIgnores', () => { | ||
describe('returns the new config object if params are valid', () => { | ||
const initialConfig = { ...getConfig() }; | ||
beforeAll(() => { | ||
const clientIds = initialConfig.dataClients.map((c) => c.clientId); | ||
const freshCfg = removeClients({ clientIds }); | ||
setConfig(freshCfg); | ||
const sourceClient = addClient(validSourceClient); | ||
setConfig(sourceClient); | ||
}); | ||
afterAll(() => { setConfig(initialConfig); }); | ||
|
||
test('returns the new config object if ignores are valid', () => { | ||
const CFG = { ...getConfig() }; | ||
const clientid = CFG.dataClients[0].clientId; | ||
const testNS = 'test'; | ||
const namespaces = [testNS]; | ||
const result = addIgnores({ clientid, namespaces }); | ||
|
||
expect(result.config).not.toBe(undefined); | ||
expect(result.dataClients).not.toBe(undefined); | ||
expect(result.dataClients[0].db.name).toBe(validSourceName); | ||
expect(result.dataClients[0].db.url).toBe(validUrl); | ||
expect(result.dataClients[0].family).toBe(validFamily); | ||
expect(result.dataClients[0].origin).toBe(undefined); | ||
expect(result.dataClients[0].type).toBe(validTypeSource); | ||
expect(result.dataClients[0].client).not.toBe(undefined); | ||
expect(result.dataClients[0].client.ignoreFields).not.toBe(undefined); | ||
expect(result.dataClients[0].client.ignoreFields[0]).toBe(testNS); | ||
expect(result.jsonConfig).not.toBe(undefined); | ||
expect(result.queries).not.toBe(undefined); | ||
}); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.