Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elin Angelow committed Jan 3, 2024
1 parent ab3d7c0 commit 13c72c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
9 changes: 7 additions & 2 deletions lib/methods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ const Methods = ({
wires.write(message, methodNotFound);
} else {
this.log('debug', 'Send Notification', message);
const wr = wires.write(message);
const wr = wires.write(
message,
() => {
throw {error: errors.NotFound};
}
);
resolve(wr);
}
});
Expand Down Expand Up @@ -229,7 +234,7 @@ const Methods = ({

}
this.log('debug', 'Not Found', data.method);
return;
return false;
}
};
};
Expand Down
6 changes: 3 additions & 3 deletions lib/wires/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const Wires = () => {
const aa = await a;
if (!aa) { // was some function already called
const f = await Promise.resolve(test(data));
if (f) { // is correct function found
f();
if (f !== false) { // is correct function found
f && f(); // if result of the test is not falsie
return true;
}
}
Expand All @@ -35,7 +35,7 @@ const Wires = () => {
* @returns {Promise<void>}
*/
async write(data, notFound) {
let satisfied = await this.test(data)
let satisfied = await this.test(data);
if(!satisfied && notFound) { // no method found
notFound();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// require('./test.methods-1');
require('./test.methods-1');
require('./test.methods-wires');
35 changes: 31 additions & 4 deletions tests/unit/test.methods-wires.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,48 @@ const Methods = require('../../lib/methods');
const Wires = require('../../lib/wires');
const wires = Wires({});
let requests = new Map();
const methods = new (Methods({
const methods1 = new (Methods({
wires,
list: requests,
config: {timeout: 1000 * 60 * 100, namespace: 'testmethods'}
}));
tap.test('Method', async(t) => {
const methods2 = new (Methods({
wires,
list: requests,
config: {timeout: 1000 * 60 * 100, namespace: 'testmethods12'}
}));
methods2.add({name: 'a.b.fn1', fn: (m) => 123});
tap.test('Wires + Methods', async(t) => {
try {
await methods1.ask({id: 1, method: 'a1', params: [123]});
} catch ({error}) {
t.same(
error.message,
'NotFound',
'method not found'
);
}
try {
await methods.ask({id: 1, method: 'a1', params: [123]});
console.log(123);
const z = await methods1.notify({method: 'a1', params: [123]});
} catch ({error}) {
t.same(
error.message,
'NotFound',
'method not found'
);
}
let {params} = await methods1.ask({method: 'a.b.fn1', params: [123]});
t.same(
params,
123,
'check response'
);
let r = await methods1.notify({method: 'a.b.fn1', params: [123]});
t.same(
await methods1.notify({method: 'a.b.fn1', params: [123]}),
true,
'check response of notification'
);
t.end();
});

0 comments on commit 13c72c0

Please sign in to comment.