Skip to content

Commit

Permalink
added, basic logic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SkeloGH committed Jan 2, 2020
1 parent 50c070e commit e2f154a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
66 changes: 66 additions & 0 deletions bin/__tests__/commands/add/ignore.test.js
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);
});
});
});
7 changes: 5 additions & 2 deletions bin/commands/add/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const commandSpec = (yargs) => {
describe: 'The client id that will skip reading from the provided namespace.',
type: 'string',
},
namespace: {
namespaces: {
alias: 'n',
demandOption: true,
describe: 'The namespaces to avoid querying upon.',
Expand All @@ -45,7 +45,9 @@ const addIgnores = (params = {}) => {
const clientOpts = newClient.client ? newClient.client : {};
let { ignoreFields = [] } = clientOpts;

ignoreFields = ignoreFields.concat(params.namespace);
if (clientIdx < 0) return CFG;

ignoreFields = ignoreFields.concat(params.namespaces);
clientOpts.ignoreFields = ldArray.uniq(ignoreFields);
newClient.client = ldObject.assign({}, clientOpts);
CFG.dataClients[clientIdx] = newClient;
Expand Down Expand Up @@ -74,4 +76,5 @@ module.exports = {
commandDesc,
commandSpec,
commandHandler,
addIgnores,
};
2 changes: 1 addition & 1 deletion dist/bin/commands/add/ignore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2f154a

Please sign in to comment.