Skip to content

Commit

Permalink
fix: inter
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed May 10, 2022
1 parent 5383939 commit 50d923c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/requests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const Request = ({
items.push(request);
return request;
},
find({meta: {idx, tag: curtag = tag} = {}} = {}) {
find({idx, tag: curtag = tag} = {}) {
return items.find(({idx: idxIn}) => (
idxIn === idx &&
tag === curtag
Expand Down
39 changes: 24 additions & 15 deletions lib/vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,37 @@ const Vector = ({
log
});

const acquireRequest = ({payload, meta, match}) => {
if (match && match.idx && match.tag) {
return requests.find(match || meta);
} else {
const found = requests.find(meta);
if (!found) {
return requests.add({
packet: {
payload,
match,
meta
},
onLocalReject: (errorFullPacket) => {
throw new Error('what todo?');
}
});
}
return found;
}
};

const pass = ({
packet: {
payload: {...payload},
payload,
meta: {...meta} = {},
match: {...match} = {}
}
}) => {
// create request
const requestTmp = requests.add({
packet: {
payload,
meta,
match
},
onLocalReject: (errorFullPacket) => {
// what to do ?
}
});
// search for previous Request
const requestFound = requests.find(packet);
// 1) cancel just created
// 2) start to work with found
const request = acquireRequest({payload, meta, match});
// start to work with found
// exec hook
// return request
};
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// require('./test.methods');
require('./test.requests');
// require('./test.vector');
// require('./test.requests');
require('./test.vector');
// require('./router/test.multi');
17 changes: 5 additions & 12 deletions tests/unit/test.requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tap.test('Request', async(t) => {
'match object should have keys: idx, tag'
);

reqPool.find({meta: {idx: rq.idx}});
reqPool.find({idx: rq.idx});
tt.type(
reqPool.find(),
'undefined',
Expand All @@ -102,29 +102,22 @@ tap.test('Request', async(t) => {
'should not find request'
);
tt.type(
reqPool.find({meta: {}}),
'undefined',
'should not find request'
);
tt.type(
reqPool.find({meta: {idx: rq.idx}}),
reqPool.find({idx: rq.idx}),
'object',
'should find request'
);
tt.type(
reqPool.find({meta: {idx: rq.idx, tag: tag0}}),
reqPool.find({idx: rq.idx, tag: tag0}),
'object',
'should find request'
);
tt.type(
reqPool.find({meta: {idx: -1}}),
reqPool.find({idx: -1}),
'undefined',
'should not find request'
);
tt.type(
reqPool.find({
meta: {idx: rq.idx, tag: 'nomatch'}
}),
reqPool.find({idx: rq.idx, tag: 'nomatch'}),
'undefined',
'should not find request'
);
Expand Down
23 changes: 22 additions & 1 deletion tests/unit/test.vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,28 @@ const vectorFactory = ({

tap.test('Vector', (l0) => {
l0.test('Simple checks and coverage', (t) => {
const v1 = vectorFactory({config: {id: Symbol('V')}});
const v1 = vectorFactory({config: {id: 'V'}});
v1.destroy();
t.end();
});

l0.test('New Request', (t) => {
const v1 = vectorFactory({config: {id: 'V'}});
v1.destroy();
t.end();
});

l0.test('Existing Request', (t) => {
const v1 = vectorFactory({config: {id: 'V'}});
v1.pass({
packet: {
payload: ['init'],
meta: {
direction: 'in',
method: 'a'
}
}
});
v1.destroy();
t.end();
});
Expand Down

0 comments on commit 50d923c

Please sign in to comment.