Skip to content

Commit

Permalink
chore(formatting): Use shared prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJones committed Apr 19, 2021
1 parent 872bb98 commit c74c6cd
Show file tree
Hide file tree
Showing 135 changed files with 5,461 additions and 5,428 deletions.
3 changes: 1 addition & 2 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
trailingComma: "es5"
semi: false
'@pact-foundation/pact-js-prettier-config'
32 changes: 16 additions & 16 deletions examples/ava/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
"use strict"
'use strict';

const axios = require("axios")
const axios = require('axios');

exports.getMeDogs = (endpoint) => {
const url = endpoint.url
const port = endpoint.port
const url = endpoint.url;
const port = endpoint.port;

return axios.request({
method: "GET",
method: 'GET',
baseURL: `${url}:${port}`,
url: "/dogs",
url: '/dogs',
headers: {
Accept: "application/json",
Accept: 'application/json',
},
})
}
});
};

exports.getMeDog = (endpoint) => {
const url = endpoint.url
const port = endpoint.port
const url = endpoint.url;
const port = endpoint.port;

return axios.request({
method: "GET",
method: 'GET',
baseURL: `${url}:${port}`,
url: "/dogs/1",
url: '/dogs/1',
headers: {
Accept: "application/json",
Accept: 'application/json',
},
})
}
});
};
76 changes: 38 additions & 38 deletions examples/ava/test/get-dog_1.spec.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
"use strict"
'use strict';

const path = require("path")
const test = require("ava")
const pact = require("@pact-foundation/pact")
const Pact = pact.Pact
const getMeDog = require("../index").getMeDog
const path = require('path');
const test = require('ava');
const pact = require('@pact-foundation/pact');
const Pact = pact.Pact;
const getMeDog = require('../index').getMeDog;

const url = "http://localhost"
const port = 8990
const url = 'http://localhost';
const port = 8990;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
consumer: "Ava Consumer Example",
provider: "Ava Provider Example",
pactfileWriteMode: "merge",
})
consumer: 'Ava Consumer Example',
provider: 'Ava Provider Example',
pactfileWriteMode: 'merge',
});

test.before("setting up Dog API expectations", async () => {
await provider.setup()
})
test.before('setting up Dog API expectations', async () => {
await provider.setup();
});

test("Dog API GET /dogs/1", async (t) => {
t.plan(1)
test('Dog API GET /dogs/1', async (t) => {
t.plan(1);

// BEGIN -
// Setup interactions for expected API response from provider
// This is done due to similar reasons of tear-up/down of database
// data in tests.
const interaction = {
state: "dog 1 exists",
uponReceiving: "a request for dog 1",
state: 'dog 1 exists',
uponReceiving: 'a request for dog 1',
withRequest: {
method: "GET",
path: "/dogs/1",
method: 'GET',
path: '/dogs/1',
headers: {
Accept: "application/json",
Accept: 'application/json',
},
},
willRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: [
{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: "(\\S+)",
generate: "rocky",
matcher: '(\\S+)',
generate: 'rocky',
}),
},
],
},
}
};

await provider.addInteraction(interaction)
await provider.addInteraction(interaction);
// END

const urlAndPort = {
url: url,
port: port,
}
const response = await getMeDog(urlAndPort)
};
const response = await getMeDog(urlAndPort);
t.deepEqual(response.data, [
{
dog: 1,
name: "rocky",
name: 'rocky',
},
])
]);

// verify with Pact, and reset expectations
await provider.verify()
})
await provider.verify();
});

test.after.always("pact.js mock server graceful shutdown", async () => {
await provider.finalize()
})
test.after.always('pact.js mock server graceful shutdown', async () => {
await provider.finalize();
});
76 changes: 38 additions & 38 deletions examples/ava/test/get-dogs.spec.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
"use strict"
'use strict';

const path = require("path")
const test = require("ava")
const pact = require("@pact-foundation/pact")
const Pact = pact.Pact
const getMeDogs = require("../index").getMeDogs
const path = require('path');
const test = require('ava');
const pact = require('@pact-foundation/pact');
const Pact = pact.Pact;
const getMeDogs = require('../index').getMeDogs;

const url = "http://localhost"
const port = 8989
const url = 'http://localhost';
const port = 8989;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
consumer: "Ava Consumer Example",
provider: "Ava Provider Example",
pactfileWriteMode: "merge",
})
consumer: 'Ava Consumer Example',
provider: 'Ava Provider Example',
pactfileWriteMode: 'merge',
});

test.before("setting up Dog API expectations", async () => {
await provider.setup()
})
test.before('setting up Dog API expectations', async () => {
await provider.setup();
});

test("Dog API GET /dogs", async (t) => {
t.plan(1)
test('Dog API GET /dogs', async (t) => {
t.plan(1);

// BEGIN -
// Setup interactions for expected API response from provider
// This is done due to similar reasons of tear-up/down of database
// data in tests.
const interaction = {
state: "i have a list of dogs",
uponReceiving: "a request for all dogs",
state: 'i have a list of dogs',
uponReceiving: 'a request for all dogs',
withRequest: {
method: "GET",
path: "/dogs",
method: 'GET',
path: '/dogs',
headers: {
Accept: "application/json",
Accept: 'application/json',
},
},
willRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: [
{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: "(\\S+)",
generate: "rocky",
matcher: '(\\S+)',
generate: 'rocky',
}),
},
],
},
}
};

await provider.addInteraction(interaction)
await provider.addInteraction(interaction);
// END

const urlAndPort = {
url: url,
port: port,
}
const response = await getMeDogs(urlAndPort)
};
const response = await getMeDogs(urlAndPort);
t.deepEqual(response.data, [
{
dog: 1,
name: "rocky",
name: 'rocky',
},
])
]);

// verify with Pact, and reset expectations
await provider.verify()
})
await provider.verify();
});

test.after.always("pact.js mock server graceful shutdown", async () => {
await provider.finalize()
})
test.after.always('pact.js mock server graceful shutdown', async () => {
await provider.finalize();
});
Loading

0 comments on commit c74c6cd

Please sign in to comment.