Skip to content

Commit

Permalink
Added test for payment window to integration test. (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgbennet authored and eanders-ms committed Dec 20, 2017
1 parent 1bbf3be commit c18c9e1
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"@types/react-split-pane": "0.1.5",
"@types/request": "0.0.31",
"@types/restify": "2.0.38",
"botbuilder": "3.9.0",
"botbuilder": "3.13.1",
"del": "2.2.2",
"electron": "1.8.1",
"electron-builder": "19.18.0",
Expand Down
48 changes: 44 additions & 4 deletions tests/integration/integration.ts
Expand Up @@ -70,7 +70,7 @@ describe("App", function(this: any) {

it("opens a window on launch", function() {
return app.client.waitUntilWindowLoaded()
.getWindowCount().should.eventually.equal(2)
.getWindowCount().should.eventually.equal(1)
.browserWindow.isMinimized().should.eventually.be.false
.browserWindow.isDevToolsOpened().should.eventually.be.false
.browserWindow.isVisible().should.eventually.be.true
Expand All @@ -91,15 +91,55 @@ describe("App", function(this: any) {
// return app.client.webContents.getZoomLevel().should.eventually.equal(0);
// });

it("sends a message to a local bot and gets a response", function() {
it("can connect to a local bot", function() {
return app.client
.waitForVisible(".addressbar-textbox input").should.eventually.be.true
.isVisible(".addressbar-botcreds").should.eventually.be.false
.isVisible(".wc-shellinput").should.eventually.be.false
.setValue(".addressbar-textbox input", "http://localhost:3978/api/messages")
.isVisible(".addressbar-botcreds").should.eventually.be.true
.click('button[class="addressbar-botcreds-connect-button"]').pause(500)
.isVisible(".wc-shellinput").should.eventually.be.true
});

it("sends a message to a local bot and gets a response", function() {
return app.client
.setValue(".wc-shellinput", "repeat this back\n")
.waitForVisible(".wc-message-group-content:nth-child(1) p").should.eventually.be.true
.getText(".wc-message-group-content:nth-child(1) p").should.eventually.equal("Message #1, you said repeat this back");
.waitForVisible(".wc-message-wrapper:nth-child(2) p").should.eventually.be.true
.getText(".wc-message-wrapper:last-child p").should.eventually.equal("Message #1, you said repeat this back");
});

it("can open a payment window", function() {
return app.client
.setValue(".wc-shellinput", "payment\n")
.waitForVisible(".wc-message-wrapper:nth-child(4) .wc-adaptive-card.hero").should.eventually.be.true
.getText(".wc-message-wrapper:last-child .ac-pushButton").should.eventually.equal("Buy")
.click(".wc-message-wrapper:last-child .ac-pushButton").pause(500)
.getWindowCount().should.eventually.equal(2);
});

it("can use a payment window", function() {
return app.client.windowByIndex(1)
.waitForVisible(".total-container .pay-button").should.eventually.be.true
.getText(".total-container .pay-button").should.eventually.equal("Pay")
.click(".total-container .pay-button")
.getAttribute(".pay-with .checkout-selector", "class").should.eventually.include("invalid-input")
.getAttribute(".ship-to .checkout-selector", "class").should.eventually.include("invalid-input")
.getAttribute(".shipping-options .checkout-selector", "class").should.eventually.include("invalid-input")
.click(".pay-with .checkout-selector").click(".pay-with .selector-items:last-child")
.waitForVisible(".cardholder-name").should.eventually.be.true
.setValue(".cardholder-name input", "Card holder name")
.click(".checkout-button-bar .save-button") //for now fill out bare minimum
.click(".ship-to .checkout-selector").click(".ship-to .selector-items:last-child")
.waitForVisible(".recipient").should.eventually.be.true
.setValue(".recipient input", "Recipient name")
.click(".checkout-button-bar .save-button") //for now fill out bare minimum;
.click(".shipping-options .checkout-selector").click(".shipping-options .selector-items:last-child")
.setValue(".email-receipt-to input", "asdf@microsoft.com")
.setValue(".phone input", "123-456-7890")
.click(".total-container .pay-button").pause(500)
.getWindowCount().should.eventually.equal(1)
.windowByIndex(0).waitForVisible(".wc-message-wrapper:nth-child(5) p").should.eventually.be.true
.getText(".wc-message-wrapper:last-child p").should.eventually.equal("Completed payment");
})
});
106 changes: 106 additions & 0 deletions tests/testBot/testBot.ts
Expand Up @@ -75,3 +75,109 @@ mainDialog.onDefault(function(session, args, next) {
session.send("%s, you said %s", getCounter(session), session.message.text);
});
bot.dialog('/', mainDialog);

//
// Payments
//
mainDialog.matches(/\bpayment\b/i, function(session, args, next) {
let buyCard = new builder.HeroCard(session);
buyCard.title("Product card")
.text("Press button to open payment window.")
.buttons([
{
"title": "Buy",
"type": "payment",
"value": paymentRequest
}
]);
let message = new builder.Message(session);
session.send(message.addAttachment(buyCard));
});
connector.onInvoke((invoke, callback) => {
let storageCtx = {
address: invoke.relatesTo,
persistConversationData: true,
conversationId: invoke.relatesTo.conversation.id
};

connector.getData(storageCtx, (err, data) => {
switch (invoke.name) {
case 'payments/update/shippingAddress':
case 'payments/update/shippingOption':
console.log("updatedshipping info");
callback(null, {}, 200);
break;

case 'payments/complete':
console.log("completed payment request");
callback(null, {result: "success"}, 200);
bot.beginDialog(invoke.relatesTo, 'checkout_receipt');
break;
}
});
});

bot.dialog('checkout_receipt', function (session, args) {
session.endDialog("Completed payment");
});

bot.dialog('checkout_failed', function (session, args) {
session.endDialog('Could not process your payment: %s', args.errorMessage);
});

var paymentRequest = {
id: "cartId",
expires: '1.00:00:00',
methodData: [{
supportedMethods: ['https://pay.microsoft.com/microsoftpay'],
data: {
mode: 'TEST',
merchantId: '12345678-abc1-23d4-5ef6-78a9b0c12d3d',
supportedNetworks: ['visa', 'mastercard'],
supportedTypes: ['credit']
}
}],
details: {
total: {
label: 'Total',
amount: { currency: 'USD', value: 1.99 },
pending: true
},
displayItems: [
{
label: "Doodad",
amount: { currency: 'USD', value: 1.99 }
}, {
label: 'Shipping',
amount: { currency: 'USD', value: '0.00' },
pending: true
}, {
label: 'Sales Tax',
amount: { currency: 'USD', value: '0.00' },
pending: true
}],
shippingOptions: [
{
"id": "GROUND",
"label": "Ground",
"amount": {
"currency": "USD",
"value": "8.95"
}
}, {
"id": "AIR",
"label": "Air",
"amount": {
"currency": "USD",
"value": "24.99"
}
}]
},
options: {
requestPayerName: true,
requestPayerEmail: true,
requestPayerPhone: true,
requestShipping: true,
shippingType: 'GROUND'
}
}

0 comments on commit c18c9e1

Please sign in to comment.