Skip to content

Commit

Permalink
wip: more typescript gardening and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Oct 9, 2018
1 parent ac4d06a commit 56843a1
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 290 deletions.
68 changes: 34 additions & 34 deletions examples/ava/test/get-dog_1.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";
"use strict"

const path = require("path");
const test = require("ava");
const pact = require("../../../dist/pact");
const Pact = pact.Pact;
const getMeDog = require("../index").getMeDog;
const path = require("path")
const test = require("ava")
const pact = require("../../../dist/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,
Expand All @@ -16,15 +16,15 @@ const provider = new Pact({
spec: 2,
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});
pactfileWriteMode: "merge",
})

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

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

// BEGIN -
// Setup interactions for expected API response from provider
Expand All @@ -37,47 +37,47 @@ test("Dog API GET /dogs/1", async t => {
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"
})
}
]
}
};
generate: "rocky",
}),
},
],
},
}

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

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

test.afterEach(async t => {
// verify with Pact, and reset expectations
await t.notThrows(provider.verify());
});
await t.notThrows(provider.verify())
})

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

const path = require("path");
const test = require("ava");
const pact = require("../../../dist/pact");
const Pact = pact.Pact;
const getMeDogs = require("../index").getMeDogs;
const path = require("path")
const test = require("ava")
const pact = require("../../../dist/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,
Expand All @@ -16,15 +16,15 @@ const provider = new Pact({
spec: 2,
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});
pactfileWriteMode: "merge",
})

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

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

// BEGIN -
// Setup interactions for expected API response from provider
Expand All @@ -37,47 +37,47 @@ test("Dog API GET /dogs", async t => {
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"
})
}
]
}
};
generate: "rocky",
}),
},
],
},
}

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

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

test.afterEach(async t => {
// verify with Pact, and reset expectations
await t.notThrows(provider.verify());
});
await t.notThrows(provider.verify())
})

test.always.after("pact.js mock server graceful shutdown", async () => {
await provider.finalize();
});
await provider.finalize()
})
48 changes: 24 additions & 24 deletions examples/e2e/test/provider.spec.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const { Verifier } = require("../../../dist/pact");
const path = require("path");
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");
const expect = chai.expect;
const { VerifierOptions } = require("@pact-foundation/pact-node");
chai.use(chaiAsPromised);
const { server, importData, animalRepository } = require("../provider.js");
const { Verifier } = require("../../../dist/pact")
const path = require("path")
const chai = require("chai")
const chaiAsPromised = require("chai-as-promised")
const expect = chai.expect
const { VerifierOptions } = require("@pact-foundation/pact-node")
chai.use(chaiAsPromised)
const { server, importData, animalRepository } = require("../provider.js")

server.post("/setup", (req, res) => {
const state = req.body.state;
const state = req.body.state

animalRepository.clear();
animalRepository.clear()
switch (state) {
case "Has no animals":
// do nothing
break;
break
default:
importData();
importData()
}

res.end();
});
res.end()
})

server.listen(8081, () => {
console.log("Animal Profile Service listening on http://localhost:8081");
});
console.log("Animal Profile Service listening on http://localhost:8081")
})

// Verify that the provider meets all consumer expectations
describe("Pact Verification", () => {
it("should validate the expectations of Matching Service", function() {
// lexical binding required here
this.timeout(10000);
this.timeout(10000)

let opts = {
provider: "Animal Profile Service",
Expand All @@ -48,12 +48,12 @@ describe("Pact Verification", () => {
pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1",
publishVerificationResult: true,
providerVersion: "1.0.0",
customProviderHeaders: ["Authorization: basic e5e5e5e5e5e5e5"]
};
customProviderHeaders: ["Authorization: basic e5e5e5e5e5e5e5"],
}

return new Verifier().verifyProvider(opts).then(output => {
console.log("Pact Verification Complete!");
console.log(output);
});
});
});
console.log("Pact Verification Complete!")
console.log(output)
})
})
})
28 changes: 14 additions & 14 deletions examples/e2e/test/publish.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const pact = require("@pact-foundation/pact-node");
const path = require("path");
const pact = require("@pact-foundation/pact-node")
const path = require("path")
const opts = {
pactFilesOrDirs: [
path.resolve(
__dirname,
"../pacts/matching_service-animal_profile_service.json"
)
"../pacts/matching_service-animal_profile_service.json",
),
],
pactBroker: "https://test.pact.dius.com.au",
pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M",
Expand All @@ -15,19 +15,19 @@ const opts = {
"1.0." +
(process.env.TRAVIS_BUILD_NUMBER
? process.env.TRAVIS_BUILD_NUMBER
: Math.floor(new Date() / 1000))
};
: Math.floor(new Date() / 1000)),
}

pact
.publishPacts(opts)
.then(() => {
console.log("Pact contract publishing complete!");
console.log("");
console.log("Head over to https://test.pact.dius.com.au/ and login with");
console.log("=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M");
console.log("=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1");
console.log("to see your published contracts.");
console.log("Pact contract publishing complete!")
console.log("")
console.log("Head over to https://test.pact.dius.com.au/ and login with")
console.log("=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
console.log("=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
console.log("to see your published contracts.")
})
.catch(e => {
console.log("Pact contract publishing failed: ", e);
});
console.log("Pact contract publishing failed: ", e)
})
Loading

0 comments on commit 56843a1

Please sign in to comment.