test(stack/namesystem): Add missing tests and update dependencies

This commit is contained in:
Pascal Precht 2020-02-20 14:14:31 +01:00 committed by Iuri Matias
parent d27aefd2b2
commit 8c8e5f7627
3 changed files with 197 additions and 1 deletions

View File

@ -40,7 +40,8 @@
"lint": "eslint src/",
"qa": "npm-run-all lint _typecheck _build",
"reset": "npx rimraf dist embark-*.tgz package",
"solo": "embark-solo"
"solo": "embark-solo",
"test": "jest"
},
"eslintConfig": {
"extends": "../../../.eslintrc.json"
@ -51,14 +52,33 @@
"embark-i18n": "^5.2.3"
},
"devDependencies": {
"@babel/core": "7.8.3",
"babel-jest": "25.1.0",
"embark-solo": "^5.2.3",
"embark-testing": "^5.2.0",
"eslint": "6.8.0",
"npm-run-all": "4.1.5",
"jest": "25.1.0",
"rimraf": "3.0.0"
},
"engines": {
"node": ">=10.17.0",
"npm": ">=6.11.3",
"yarn": ">=1.19.1"
},
"jest": {
"collectCoverage": true,
"testEnvironment": "node",
"testMatch": [
"**/test/**/*.js"
],
"transform": {
"\\.js$": [
"babel-jest",
{
"rootMode": "upward"
}
]
}
}
}

View File

@ -0,0 +1,173 @@
import sinon from 'sinon';
import assert from 'assert';
import { fakeEmbark, Plugins } from 'embark-testing';
import Namesystem from '../src';
describe('stack/namesystem', () => {
let namesystem, embark;
beforeEach(() => {
const testBed = fakeEmbark({
namesystemConfig: {
provider: 'testNode',
enabled: true
}
});
embark = testBed.embark;
namesystem = new Namesystem(embark);
});
afterEach(() => {
embark.teardown();
sinon.restore();
});
describe('instantiation', () => {
it('should register namesystem:node:register command handler', () => {
namesystem.events.assert.commandHandlerRegistered('namesystem:node:register');
});
it('should register namesystem:node:start command handler', () => {
namesystem.events.assert.commandHandlerRegistered('namesystem:node:start');
});
it('should register namesystem:resolve command handler', () => {
namesystem.events.assert.commandHandlerRegistered('namesystem:resolve');
});
it('should register namesystem:lookup command handler', () => {
namesystem.events.assert.commandHandlerRegistered('namesystem:lookup');
});
it('should register namesystem:registerSubdomain command handler', () => {
namesystem.events.assert.commandHandlerRegistered('namesystem:registerSubdomain');
});
it('should register module:namesystem:reset command handler', () => {
namesystem.events.assert.commandHandlerRegistered('module:namesystem:reset');
});
});
it('should register node', () => {
const startFunction = sinon.fake();
const executeCommand = sinon.fake();
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
assert(namesystem.namesystemNodes['testNode']);
assert.equal(namesystem.namesystemNodes['testNode'].started, false);
});
it('should start registered node', done => {
const startFunction = sinon.spy(cb => cb());
const executeCommand = sinon.fake();
const namesystemConfig = {
provider: 'testNode',
enabled: true
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
embark.events.request('namesystem:node:start', namesystemConfig, err => {
assert(startFunction.calledOnce);
assert.equal(namesystem.namesystemNodes['testNode'].started, true);
done();
});
});
it('should not start node if namesystem is disabled', done => {
const startFunction = sinon.fake();
const executeCommand = sinon.fake();
const namesystemConfig = {
provider: 'testNode',
enabled: false
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
embark.events.request('namesystem:node:start', namesystemConfig, err => {
assert(!startFunction.calledOnce);
done();
});
});
it('should resolve name using registered node', async () => {
const startFunction = sinon.spy(cb => cb());
const executeCommand = sinon.spy((method, args, cb) => cb());
const namesystemConfig = {
provider: 'testNode',
enabled: true
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
await embark.events.request2('namesystem:node:start', namesystemConfig);
await embark.events.request2('namesystem:resolve', 'someName');
assert(executeCommand.calledOnce);
assert(executeCommand.calledWith('resolve', ['someName']));
});
it('should lookup address using registered node', async () => {
const startFunction = sinon.spy(cb => cb());
const executeCommand = sinon.spy((method, args, cb) => cb());
const namesystemConfig = {
provider: 'testNode',
enabled: true
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
await embark.events.request2('namesystem:node:start', namesystemConfig);
await embark.events.request2('namesystem:lookup', '0x000');
assert(executeCommand.calledOnce);
assert(executeCommand.calledWith('lookup', ['0x000']));
});
it('should register subdomain using registered node', async () => {
const startFunction = sinon.spy(cb => cb());
const executeCommand = sinon.spy((method, args, cb) => cb());
const namesystemConfig = {
provider: 'testNode',
enabled: true
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
await embark.events.request2('namesystem:node:start', namesystemConfig);
await embark.events.request2('namesystem:registerSubdomain', 'someName', '0x000');
assert(executeCommand.calledOnce);
assert(executeCommand.calledWith('registerSubdomain', ['someName', '0x000']));
});
it('should reset namesystem', async () => {
const startFunction = sinon.spy(cb => cb());
const executeCommand = sinon.spy((method, args, cb) => cb());
const namesystemConfig = {
provider: 'testNode',
enabled: true
};
embark.events.request('namesystem:node:register', 'testNode', startFunction, executeCommand);
await embark.events.request2('namesystem:node:start', namesystemConfig);
await embark.events.request2('module:namesystem:reset');
assert(executeCommand.calledOnce);
assert(executeCommand.calledWith('reset', []));
assert(startFunction.calledTwice);
});
});

View File

@ -12,6 +12,9 @@
"references": [
{
"path": "../../core/i18n"
},
{
"path": "../../utils/testing"
}
]
}