Skip to content

Commit

Permalink
GH-47 Make acceptance test consistently green
Browse files Browse the repository at this point in the history
  • Loading branch information
ceilfors committed Jun 6, 2019
1 parent ed64adc commit bce8472
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Expand Up @@ -90,7 +90,6 @@ class WebSocketOrderMessenger {
_waitForMessage(messageType) {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
this.ws.close();
reject(
new Error(`Did not get any ${messageType} message from web socket`)
);
Expand All @@ -104,7 +103,6 @@ class WebSocketOrderMessenger {
this.ws.on("error", err => {
console.log("websocket error", err);
clearTimeout(timeout);
this.ws.close();
reject(err);
});
});
Expand All @@ -120,6 +118,9 @@ class WebSocketOrderMessenger {

orderReceived() {
this.ws.send(JSON.stringify({ message: "order received" }));
}

close() {
this.ws.close();
}
}
Expand Down Expand Up @@ -192,6 +193,10 @@ describe("order flow", () => {
orderMessagePromise = orderMessenger.waitForOrderAcceptedMessage();
});

afterAll(() => {
orderMessenger.close();
});

describe("happy path", () => {
it("should store all placed orders in Order Table", async () => {
Object.keys(orderMap).forEach(async orderId => {
Expand Down Expand Up @@ -224,7 +229,7 @@ describe("order flow", () => {
expect(JSON.parse(thankYouMessage).message).toEqual(
"thank you for your order"
);
}, 20000);
}, 10000);

it("should capture all card payments", async () => {
await laconiaTest(name("process-card-payments")).fireAndForget();
Expand Down
2 changes: 1 addition & 1 deletion packages/laconia-acceptance-test/src/WebSocketClient.js
Expand Up @@ -14,7 +14,7 @@ module.exports = class WebSocketClient {
}

send(message) {
console.log("send", message, this.connectionId, message);
console.log("Sending to websocket client", this.connectionId, message);
return this.client
.postToConnection({
ConnectionId: this.connectionId,
Expand Down
8 changes: 5 additions & 3 deletions packages/laconia-acceptance-test/src/update-user-receipt.js
Expand Up @@ -9,12 +9,14 @@ const instances = ({ event, env }) => ({
)
});

const app = async (messageBody, { wsClient }) => {
if (messageBody.message === "order accepted") {
const app = async (message, { wsClient }) => {
if (message.body.message === "order received") {
return wsClient.send({ message: "thank you for your order" });
}
};

const webSocket = adapterApi.webSocket();

exports.handler = laconia(webSocket(app)).register(instances);
exports.handler = laconia(webSocket(app)).register(instances, {
cache: { enabled: false }
});

0 comments on commit bce8472

Please sign in to comment.