Skip to content

Commit

Permalink
Added feature scenarios as living documentation
Browse files Browse the repository at this point in the history
Increased integration test coverage
  • Loading branch information
bashj79 committed Mar 9, 2021
1 parent 42c070f commit dc865bf
Show file tree
Hide file tree
Showing 18 changed files with 3,039 additions and 946 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM bbyars/mountebank:2.4.0

ENV MB_GRAPHQL_VERSION=0.1.5
ENV MB_GRAPHQL_VERSION=0.1.6
RUN npm install -g mb-graphql@${MB_GRAPHQL_VERSION} --production

RUN mkdir /mb-graphql
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Wraps [Apollo Server](https://www.apollographql.com/docs/apollo-server) to allow
server via mountebank `stubs` (see below).

## Run with Docker (the easiest option)

```
docker run -p 2525:2525 [-p IMPOSTER_PORT:IMPOSTER_PORT] -d bashj79/mountebank-graphql
```

NOTE: mountebank itself runs on port 2525.

Check out [Docker Hub](https://hub.docker.com/r/bashj79/mountebank-graphql) for further details.
Expand All @@ -24,7 +26,8 @@ Prerequisite:
npm install -g mb-graphql
```

Start mountebank with the following `protocols.json` file ([master on GitHub](https://github.com/bashj79/mb-graphql/blob/master/protocols.json)):
Start mountebank with the following `protocols.json`
file ([master on GitHub](https://github.com/bashj79/mb-graphql/blob/master/protocols.json)):

```json
{
Expand All @@ -40,6 +43,8 @@ mb start --protofile protocols.json

## Example

For further examples please check out the [features](https://github.com/bashj79/mb-graphql/tree/main/src) folder.

`imposter.json`

```json
Expand Down
6 changes: 6 additions & 0 deletions features/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../.eslintrc",
"rules": {
"import/no-extraneous-dependencies": "off"
}
}
240 changes: 240 additions & 0 deletions features/queryImposterCreatedFromGraphQLSchemaEndpoint.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
Feature: Create imposter from Schema Endpoint
Allow querying of GraphQL imposter having a remote schema definition

Scenario: Query imposter with endpoint with accessible introspection query
Given a GraphQL server exists at "http://localhost:3000" with the following schema definition:
"""
type Thing {
alpha: Int
beta: String
}
input ThingInput {
alpha: Int!
beta: String!
}
type Query {
dummyQuery: String
}
type Mutation {
myMutation(data: ThingInput!): Thing
}
"""
And a GraphQL imposter exists on port 4000 configured with the "http://localhost:3000" schema endpoint
And the imposter's single stub has the following predicates:
"""
[
{
"equals": {
"mutation": "myMutation"
}
},
{
"equals": {
"args": {
"data": {
"alpha": 42,
"beta": "abcdef"
}
}
}
}
]
"""
And the imposter's single stub has the following responses:
"""
[
{
"is": {
"data": {
"alpha": 24,
"beta": "fedcba"
}
}
}
]
"""
When Brandon attempts to execute the following GraphQL query:
"""
mutation {
myMutation(data: {
alpha: 42
beta: "abcdef"
}) {
beta
alpha
}
}
"""
Then the query will be successful and the response will be:
"""
{
"data": {
"myMutation": {
"beta": "fedcba",
"alpha": 24
}
}
}
"""

Scenario: Query imposter with endpoint with accessible introspection query requiring authentication
Given a secure GraphQL server requiring the "my.access.token" bearer token exists at "http://localhost:3001" with the following schema definition:
"""
type Thing {
alpha: Int
beta: String
}
input ThingInput {
alpha: Int!
beta: String!
}
type Query {
dummyQuery: String
}
type Mutation {
mySecureMutation(data: ThingInput!): Thing
}
"""
And a GraphQL imposter exists on port 4000 configured with the "http://localhost:3001" schema endpoint and the following schema endpoint headers:
| Authorization | Bearer my.access.token |
And the imposter's single stub has the following predicates:
"""
[
{
"equals": {
"mutation": "mySecureMutation"
}
},
{
"equals": {
"args": {
"data": {
"alpha": 42,
"beta": "abcdef"
}
}
}
}
]
"""
And the imposter's single stub has the following responses:
"""
[
{
"is": {
"data": {
"alpha": 24,
"beta": "fedcba"
}
}
}
]
"""
When Ivan attempts to execute the following GraphQL query:
"""
mutation {
mySecureMutation(data: {
alpha: 42
beta: "abcdef"
}) {
beta
alpha
}
}
"""
Then the query will be successful and the response will be:
"""
{
"data": {
"mySecureMutation": {
"beta": "fedcba",
"alpha": 24
}
}
}
"""

Scenario: Query imposter with remotely hosted schema definition
Given a following schema definition exists at the "http://localhost:8080/schema.graphql" URL:
"""
type OtherThing {
alpha: Int
beta: String
}
input OtherThingInput {
alpha: Int!
beta: String!
}
type Query {
dummyQuery: String
}
type Mutation {
myOtherMutation(data: OtherThingInput!): OtherThing
}
"""
And a GraphQL imposter exists on port 4000 configured with the "http://localhost:8080/schema.graphql" schema endpoint
And the imposter's single stub has the following predicates:
"""
[
{
"equals": {
"mutation": "myOtherMutation"
}
},
{
"equals": {
"args": {
"data": {
"alpha": 123,
"beta": "abc"
}
}
}
}
]
"""
And the imposter's single stub has the following responses:
"""
[
{
"is": {
"data": {
"alpha": 456,
"beta": "def"
}
}
}
]
"""
When Lee attempts to execute the following GraphQL query:
"""
mutation {
myOtherMutation(data: {
alpha: 123
beta: "abc"
}) {
beta
alpha
}
}
"""
Then the query will be successful and the response will be:
"""
{
"data": {
"myOtherMutation": {
"beta": "def",
"alpha": 456
}
}
}
"""
82 changes: 82 additions & 0 deletions features/queryImposterCreatedFromInlineGraphQLSchema.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Feature: Create imposter from Inline Schema
Allow querying of GraphQL imposter having an inline schema definition

Background:
Given a GraphQL imposter exists on port 4000 with the following inline schema definition:
"""
type Thing {
alpha: Int
beta: String
}
type Query {
myQuery(myFirstArg: Int, mySecondArg: Int): Thing
}
"""
And the imposter's single stub has the following predicates:
"""
[
{
"equals": {
"query": "myQuery"
}
},
{
"equals": {
"args": {
"myFirstArg": 123
}
}
}
]
"""
And the imposter's single stub has the following responses:
"""
[
{
"is": {
"data": {
"alpha": 42,
"beta": "abcdef"
}
}
}
]
"""

Scenario: Query imposter with exact predicate match
When Brandon attempts to execute the following GraphQL query:
"""
query {
myQuery(myFirstArg: 123) {
alpha
beta
}
}
"""
Then the query will be successful and the response will be:
"""
{
"data": {
"myQuery": {
"alpha": 42,
"beta": "abcdef"
}
}
}
"""

Scenario: Query imposter with incomplete predicate match
When Ivan attempts to execute the following GraphQL query:
"""
query {
myQuery(myFirstArg: 456) {
alpha
beta
}
}
"""
Then the query will be successful and the response will match:
| JSON Path | Value Type |
| data.myQuery.alpha | Number |
| data.myQuery.beta | String |
4 changes: 4 additions & 0 deletions features/support/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable no-console */
export default (message) => {
console.log(message);
};
Loading

0 comments on commit dc865bf

Please sign in to comment.