Skip to content

Commit

Permalink
fix: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed Jun 7, 2022
1 parent ce58c67 commit 17c30ae
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 25 deletions.
12 changes: 10 additions & 2 deletions lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ const defaultLog = (level, message) => {};
// two vector implementation
const Router = ({
log = defaultLog,
vectors: [V1, V2]
vectors: [V0, V1]
} = {}) => {
const vectors = new Map();
vectors.set(0, V0);
vectors.set(1, V1);

const pass = async({vector, packet}) => {
};

return {
log
log,
pass
};
};

Expand Down
25 changes: 23 additions & 2 deletions tests/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const methodRegisterFactory = (
});
};

const passFactory = (
const vectorPassFactory = (
vector,
payload,
error,
Expand All @@ -64,9 +64,30 @@ const passFactory = (
});
};

const routerPassFactory = (
router,
payload,
error,
[method, direction],
match = {}
) => {
return router.pass({
packet: {
...(payload && {payload: payload.concat([`>${method}.${direction}`])}),
...(error && {error}),
meta: {
method,
direction
},
match
}
});
};

module.exports = {
methodRegisterFactory,
timeOut,
vectorFactory,
passFactory
vectorPassFactory,
routerPassFactory
};
4 changes: 2 additions & 2 deletions tests/unit/router/test.router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tap = require('tap');
const Router = require('../../../lib/router');
const {
passFactory,
routerPassFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand Down Expand Up @@ -29,7 +29,7 @@ tap.test('Router', (l0) => {

router.pass({
vector: 0,

packet:
})

l0.end();
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/vector/test.in-na-out-na.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const tap = require('tap');
const {
timeOut,
vectorFactory,
vectorPassFactory,
methodRegisterFactory
} = require('../helpers');

Expand All @@ -23,14 +25,14 @@ methodRegisterFactory(v1, '*.out', ({payload, ...pass}) => {

tap.test('Vector: In and Out Method don\'t exists', async(l0) => {
try {
const r1 = await passFactory(
const r1 = await vectorPassFactory(
v1,
['UnExisting Method aa.in existing a.out'],
false,
['aa', 'in']
);
const p = timeOut(async() => {
const r2 = await passFactory(
const r2 = await vectorPassFactory(
v1,
r1.payload,
r1.error,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/vector/test.in-na-out-ok.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tap = require('tap');
const {
passFactory,
vectorPassFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand All @@ -12,14 +12,14 @@ methodRegisterFactory(v1, 'a.out');

tap.test('Vector: In Method don\'t exists', async(l0) => {
try {
const r1 = await passFactory(
const r1 = await vectorPassFactory(
v1,
['UnExisting Method aa.in existing a.out'],
false,
['aa', 'in']
);
const p = timeOut(async() => {
const r2 = await passFactory(
const r2 = await vectorPassFactory(
v1,
r1.payload,
r1.error,
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/vector/test.in-ok-out-na.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tap = require('tap');
const {
passFactory,
vectorPassFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand All @@ -12,14 +12,14 @@ methodRegisterFactory(v1, 'a.out');

tap.test('Vector: Out Method don\'t exists', async(l0) => {
try {
const r1 = await passFactory(
const r1 = await vectorPassFactory(
v1,
['UnExisting Method aa.in existing a.out'],
false,
['a', 'in']
);
const p = timeOut(async() => {
const r2 = await passFactory(
const r2 = await vectorPassFactory(
v1,
r1.payload,
r1.error,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/vector/test.in-out-ok.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tap = require('tap');
const {
passFactory,
vectorPassFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand All @@ -12,14 +12,14 @@ methodRegisterFactory(v1, 'a.out');

tap.test('Vector: Existing Methods a.in and a.out', async(l0) => {
try {
const r1 = await passFactory(
const r1 = await vectorPassFactory(
v1,
['Existing Methods a.in and a.out, dir in > out'],
false,
['a','in']
);
setTimeout(async() => {
await passFactory(
await vectorPassFactory(
v1,
r1.payload,
false,
Expand All @@ -40,14 +40,14 @@ tap.test('Vector: Existing Methods a.in and a.out', async(l0) => {
match: {idx: 1, tag: Symbol('V')}
}, 'packet struct should match, direction in > out');

const r2 = await passFactory(
const r2 = await vectorPassFactory(
v1,
['Existing Methods a.in and a.out, dir out > in'],
false,
['a', 'out']
);
setTimeout(async() => {
await passFactory(
await vectorPassFactory(
v1,
r2.payload,
false,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/vector/test.special.method.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tap = require('tap');
const {
passFactory,
vectorPassFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand Down Expand Up @@ -28,14 +28,14 @@ methodRegisterFactory(w1, 'a.out');

tap.test('Vector: Special method (*) success cases', async(l0) => {
try {
const r1 = await passFactory(
const r1 = await vectorPassFactory(
v1,
['Existing Methods a.in and a.out, dir in > out, special(*) method should be called'],
false,
['a', 'in']
);
setTimeout(async() => {
await passFactory(
await vectorPassFactory(
v1,
r1.payload,
false,
Expand All @@ -57,14 +57,14 @@ tap.test('Vector: Special method (*) success cases', async(l0) => {
match: {idx: 1, tag: Symbol('V')}
}, 'packet struct should match, direction in > out');
//////////////////////////////////
const r2 = await passFactory(
const r2 = await vectorPassFactory(
w1,
['Existing Methods a.in and a.out, dir in > out, special(*) method called should be skipped'],
false,
['a', 'in']
);
setTimeout(async() => {
await passFactory(
await vectorPassFactory(
w1,
r2.payload,
false,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/vector/test.vector.simple-checks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const tap = require('tap');
const {
passFactory,
timeOut,
vectorFactory,
methodRegisterFactory
Expand Down

0 comments on commit 17c30ae

Please sign in to comment.