Skip to content

Commit

Permalink
test: fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Ottun committed Oct 17, 2021
1 parent eb47dc3 commit ce9c0a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/engine/assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test('at most 1 time and at least 1 time', async () => {
headers: {},
};

await engine.execute(get);
await engine.execute(post);
await engine.execute(get);

const verificationPost: Verification = {
Expand All @@ -57,7 +57,7 @@ test('at most 1 time and at least 1 time', async () => {
request: get,
limit: { atLeast: 1 },
};
const verifiedGet = engine.assert(verificationGet);
const verifiedGet: any = engine.assert(verificationGet);
expect(verifiedGet).toMatchInlineSnapshot(`true`);
});

Expand Down
17 changes: 7 additions & 10 deletions src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,12 @@ export class Engine extends EventEmitter {
}

private verifyRequest(request: Request): Record[] {
return (
this.$records
.filter((rec) => methodMatcher(request, rec.request))
.filter((rec) => rec.request.path === request.path)
.filter((rec) => headerMatcher(request, rec.request))
.filter((rec) => bodyMatcher(request, rec.request))
// .filter((rec) => rec.matches.length > 0)
.sort((a, b) => a.timestamp - b.timestamp)
);
return this.$records
.filter((rec) => methodMatcher(request, rec.request))
.filter((rec) => rec.request.path === request.path)
.filter((rec) => headerMatcher(request, rec.request))
.filter((rec) => bodyMatcher(request, rec.request))
.sort((a, b) => a.timestamp - b.timestamp);
}

private createProxy = (request: Request): Proxy => {
Expand Down Expand Up @@ -226,7 +223,7 @@ export class Engine extends EventEmitter {
const matches = this.verifyRequest(request);

// set the lower and upper limits
const verifyLimit = Object.assign({ atMost: 'unlimited', atLeast: limit.atMost ? 0 : 1 }, limit);
const verifyLimit = Object.assign({ atMost: 'unlimited', atLeast: 1 }, limit);

// lower limit check with an unlimited upper limit
if (verifyLimit.atMost === 'unlimited' && matches.length >= verifyLimit.atLeast) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ const createRequestRouter = ({ engine }: Props) => {
router.put('/assert', (req, res, next) => {
try {
// @ts-ignore
const mock = req.payload;
const verified = mock.map((verify: Verification) => engine.assert(verify));
const verifications = req.payload;
const verified = verifications.map((verify: Verification) => engine.assert(verify));
const passed = verified.filter((res) => typeof res !== 'boolean');

if (passed.length !== 0) {
Expand Down

0 comments on commit ce9c0a4

Please sign in to comment.