-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(message): tidy up Message interface and tests
- Loading branch information
Showing
11 changed files
with
176 additions
and
44 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
Empty file.
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,96 @@ | ||
import * as chai from "chai"; | ||
import * as chaiAsPromised from "chai-as-promised"; | ||
import { GraphQLInteraction } from "./graphql"; | ||
import { Interaction } from "../pact"; | ||
import { isMatcher, regex } from "./matchers"; | ||
|
||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
|
||
describe("GraphQLInteraction", () => { | ||
let interaction: GraphQLInteraction; | ||
|
||
beforeEach(() => { | ||
interaction = new GraphQLInteraction(); | ||
}); | ||
|
||
describe("#withOperation", () => { | ||
describe("when given a valid operation", () => { | ||
it("should not fail", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withOperation("query"); | ||
interaction.withQuery("{ hello }"); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body.operationName).to.eq("query"); | ||
}); | ||
}); | ||
describe("when no operation is provided", () => { | ||
it("should marshal to null", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withQuery("{ hello }"); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body.operationName).to.eq(null); | ||
}); | ||
}); | ||
describe("when given an invalid operation", () => { | ||
it("should fail with an error", () => { | ||
expect(interaction.withOperation.bind("aoeu")).to.throw(Error); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#withVariables", () => { | ||
describe("when given a set of variables", () => { | ||
it("should add the variables to the payload", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withOperation("query"); | ||
interaction.withQuery("{ hello }"); | ||
interaction.withVariables({ | ||
foo: "bar", | ||
}); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body.variables).to.deep.eq({ foo: "bar" }); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#withQuery", () => { | ||
beforeEach(() => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withOperation("query"); | ||
interaction.withQuery("{ hello }"); | ||
interaction.withVariables({ | ||
foo: "bar", | ||
}); | ||
}); | ||
|
||
describe("when given an invalid query", () => { | ||
it("should fail with an error", () => { | ||
expect(() => interaction.withQuery("{ not properly terminated")).to.throw(Error); | ||
}); | ||
}); | ||
|
||
describe("when given a valid valid query", () => { | ||
it("should properly marshal the query", () => { | ||
const json: any = interaction.json(); | ||
expect(isMatcher(json.request.body.query)).to.eq(true); | ||
expect(json.request.body.query.getValue()).to.eq("{ hello }"); | ||
}); | ||
|
||
it("should add regular expressions for the whitespace in the query", () => { | ||
const json: any = interaction.json(); | ||
|
||
expect(isMatcher(json.request.body.query)).to.eq(true); | ||
const r = new RegExp(json.request.body.query.data.matcher.s, "g"); | ||
const lotsOfWhitespace = `{ hello | ||
}`; | ||
expect(r.test(lotsOfWhitespace)).to.eq(true); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
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
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
Oops, something went wrong.