-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from AngelaE/query-string
Add Query String to FlexiPredicate
- Loading branch information
Showing
8 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
integration-tests/src/predicate.flexi-predicate.body.mb-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { expect } from 'chai'; | ||
import request = require('superagent'); | ||
|
||
import { | ||
Imposter, | ||
Mountebank, | ||
Stub, | ||
FlexiPredicate, | ||
Operator, | ||
DefaultResponse, | ||
} from '@anev/ts-mountebank'; | ||
|
||
const port = 12345; | ||
const path = '/testpath'; | ||
async function getImposterResponseCode(body: any): Promise<number> { | ||
return (await request.post(`http://localhost:${port}${path}`).send(body)) | ||
.statusCode; | ||
} | ||
|
||
describe('The flexi predicate works with query', () => { | ||
// only runs on local machine for now | ||
const mb = new Mountebank(); | ||
|
||
const tests = [ | ||
{ | ||
predicateBody: {name: 'x', max: 5}, | ||
matches: [{name: 'x', max: 5}, {name: 'x', max: 5, min: 1}], | ||
nonMatching: [{name: 'x'}, {name: 'x', max: 6}], | ||
}, | ||
|
||
]; | ||
|
||
tests.forEach(async (test) => { | ||
describe(`Body works for predicate '${JSON.stringify(test.predicateBody)}'`, () => { | ||
before(async () => { | ||
const imposter = new Imposter() | ||
.withPort(port) | ||
.withStub( | ||
new Stub() | ||
.withPredicate( | ||
new FlexiPredicate() | ||
.withOperator(Operator.equals) | ||
.withPath(path) | ||
.withBody(test.predicateBody) | ||
) | ||
.withResponse(new DefaultResponse('found', 222)) | ||
); | ||
|
||
await mb.createImposter(imposter); | ||
}); | ||
|
||
test.matches.forEach(async (match) => { | ||
it(`works with match '${JSON.stringify(match)}'`, async () => { | ||
// assert | ||
const responseCode = await getImposterResponseCode(match); | ||
expect(responseCode).to.equal(222); | ||
}); | ||
}); | ||
|
||
test.nonMatching.forEach(async (nonMatch) => { | ||
it(`does not work with '${JSON.stringify(nonMatch)}'`, async () => { | ||
// assert | ||
const responseCode = await getImposterResponseCode(nonMatch); | ||
expect(responseCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
integration-tests/src/predicate.flexi-predicate.query.mb-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { expect } from 'chai'; | ||
import request = require('superagent'); | ||
|
||
import { | ||
Imposter, | ||
Mountebank, | ||
Stub, | ||
FlexiPredicate, | ||
Operator, | ||
DefaultResponse, | ||
} from '@anev/ts-mountebank'; | ||
|
||
const port = 12345; | ||
const path = '/testpath'; | ||
async function getImposterResponseCode(queryString: string): Promise<number> { | ||
return (await request.get(`http://localhost:${port}${path}?${queryString}`)).statusCode; | ||
} | ||
|
||
describe('The flexi predicate works with query', () => { | ||
// only runs on local machine for now | ||
const mb = new Mountebank(); | ||
|
||
const tests = [ | ||
{ | ||
predicateQuery: {name: 'x', max: 5}, | ||
matches: ['name=x&max=5', 'max=5&name=x', 'MAX=5&namE=X', 'name=x&max=5&another=y'], | ||
nonMatching: ['max=5', 'name=x&max=6'], | ||
}, | ||
|
||
]; | ||
|
||
tests.forEach(async (test) => { | ||
describe(`Query works for predicate '${JSON.stringify(test.predicateQuery)}'`, () => { | ||
before(async () => { | ||
const imposter = new Imposter() | ||
.withPort(port) | ||
.withStub( | ||
new Stub() | ||
.withPredicate( | ||
new FlexiPredicate() | ||
.withOperator(Operator.equals) | ||
.withPath(path) | ||
.withQuery(test.predicateQuery) | ||
) | ||
.withResponse(new DefaultResponse('found', 222)) | ||
); | ||
|
||
await mb.createImposter(imposter); | ||
}); | ||
|
||
test.matches.forEach(async (match) => { | ||
it(`works with match '${match}'`, async () => { | ||
// assert | ||
const responseCode = await getImposterResponseCode(match); | ||
expect(responseCode).to.equal(222); | ||
}); | ||
}); | ||
|
||
test.nonMatching.forEach(async (nonMatch) => { | ||
it(`does not work with '${nonMatch}'`, async () => { | ||
// assert | ||
const responseCode = await getImposterResponseCode(nonMatch); | ||
expect(responseCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters