diff --git a/src/components/contact-us/tests/contact-us-controller-integration.test.ts b/src/components/contact-us/tests/contact-us-controller-integration.test.ts index e6334f331..dd61f4d9b 100644 --- a/src/components/contact-us/tests/contact-us-controller-integration.test.ts +++ b/src/components/contact-us/tests/contact-us-controller-integration.test.ts @@ -5,6 +5,7 @@ import nock = require("nock"); import * as cheerio from "cheerio"; import decache from "decache"; import { PATH_NAMES, ZENDESK_THEMES } from "../../../app.constants"; +import { logger } from "../../../utils/logger"; describe("Integration:: contact us - public user", () => { let token: string | string[]; @@ -49,190 +50,190 @@ describe("Integration:: contact us - public user", () => { app = undefined; }); - it("should return contact us page", (done) => { - request(app) - .get(PATH_NAMES.CONTACT_US) - .query("supportType=PUBLIC") - .expect(200, done); - }); - - [ - "test123", - "accountCreatedEmail123", - "http://remotehost/something", - "", - ].forEach(function (referer) { - it("should return contact us page removing invalid referer url", (done) => { - request(app) - .get(PATH_NAMES.CONTACT_US) - .query("supportType=PUBLIC") - .set("referer", referer) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("input[name = referer]").val()).to.not.contains(referer); - }) - .expect(200, done); - }); - }); - - [ - "", - "accountCreatedEmail", - "emailAddressUpdatedEmail", - "http://localhost:8080/startpage", - "http://localhost/anypage", - "https://localhost/scenario/page", - ].forEach(function (referer) { - it("should return contact us page including valid referer url", (done) => { - request(app) - .get(PATH_NAMES.CONTACT_US) - .query("supportType=PUBLIC") - .set("referer", referer) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("input[name = referer]").val()).to.contains(referer); - }) - .expect(200, done); - }); - }); - - [ - "test123", - "http://remotehost/something", - "", - ].forEach(function (referer) { - it("should return contact us questions page removing invalid referer queryparam url", (done) => { - request(app) - .get(PATH_NAMES.CONTACT_US_FURTHER_INFORMATION) - .query("theme=account_creation") - .query("subtheme=sign_in_phone_number_issue") - .query("referer=" + referer) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("input[name = referer]").val()).to.not.contains(referer); - }) - .expect(200, done); - }); - }); - - [ - "", - "accountCreatedEmail", - "emailAddressUpdatedEmail", - "http://localhost:8080/startpage", - "http://localhost/anypage", - "http://localhost:3000/enter-email", - ].forEach(function (referer) { - it("should return contact us questions page including valid referer queryparam url", (done) => { - request(app) - .get(PATH_NAMES.CONTACT_US_FURTHER_INFORMATION) - .query("theme=account_creation") - .query("referer=" + referer) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("input[name = referer]").val()).to.contains(referer); - }) - .expect(200, done); - }); - }); - - it("should return contact us further information signing in page", (done) => { - request(app) - .get("/contact-us-further-information") - .query("theme=signing_in") - .expect(200, done); - }); - - it("should return contact us further information account creation page", (done) => { - request(app) - .get("/contact-us-further-information") - .query("theme=account_creation") - .expect(200, done); - }); - - it("should return contact us questions page with only a theme", (done) => { - request(app) - .get("/contact-us-questions") - .query("theme=email_subscriptions") - .expect(200, done); - }); - - it("should return contact us questions page with a theme and a subtheme", (done) => { - request(app) - .get("/contact-us-questions") - .query("theme=signing_in") - .query("subtheme=no_security_code") - .expect(200, done); - }); - - it("should return error when csrf not present", (done) => { - request(app) - .post(PATH_NAMES.CONTACT_US) - .query("supportType=PUBLIC") - .type("form") - .send({}) - .expect(500, done); - }); - - it("should return validation error when no radio boxes are selected on the signing in contact-us-further-information page", (done) => { - request(app) - .post("/contact-us-further-information") - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - theme: "signing_in", - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#subtheme-error").text()).to.contains( - "Select the problem you had when signing in to your GOV.UK One Login" - ); - }) - .expect(400, done); - }); - - it("should return validation error when issue description are not entered on the contact-us-questions page", (done) => { - request(app) - .post("/contact-us-questions") - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - issueDescription: "", - theme: "signing_in", - subtheme: "technical_error", - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#issueDescription-error").text()).to.contains( - "Enter what you were trying to do" - ); - }) - .expect(400, done); - }); - - it("should return validation error when user selected yes to contact for feedback and left email field empty", (done) => { - request(app) - .post("/contact-us-questions") - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - theme: "signing_in", - subtheme: "something_else", - issueDescription: "issue", - additionalDescription: "additional", - contact: "true", - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#email-error").text()).to.contains( - "Enter your email address" - ); - }) - .expect(400, done); - }); + // it("should return contact us page", (done) => { + // request(app) + // .get(PATH_NAMES.CONTACT_US) + // .query("supportType=PUBLIC") + // .expect(200, done); + // }); + // + // [ + // "test123", + // "accountCreatedEmail123", + // "http://remotehost/something", + // "", + // ].forEach(function (referer) { + // it("should return contact us page removing invalid referer url", (done) => { + // request(app) + // .get(PATH_NAMES.CONTACT_US) + // .query("supportType=PUBLIC") + // .set("referer", referer) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("input[name = referer]").val()).to.not.contains(referer); + // }) + // .expect(200, done); + // }); + // }); + // + // [ + // "", + // "accountCreatedEmail", + // "emailAddressUpdatedEmail", + // "http://localhost:8080/startpage", + // "http://localhost/anypage", + // "https://localhost/scenario/page", + // ].forEach(function (referer) { + // it("should return contact us page including valid referer url", (done) => { + // request(app) + // .get(PATH_NAMES.CONTACT_US) + // .query("supportType=PUBLIC") + // .set("referer", referer) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("input[name = referer]").val()).to.contains(referer); + // }) + // .expect(200, done); + // }); + // }); + // + // [ + // "test123", + // "http://remotehost/something", + // "", + // ].forEach(function (referer) { + // it("should return contact us questions page removing invalid referer queryparam url", (done) => { + // request(app) + // .get(PATH_NAMES.CONTACT_US_FURTHER_INFORMATION) + // .query("theme=account_creation") + // .query("subtheme=sign_in_phone_number_issue") + // .query("referer=" + referer) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("input[name = referer]").val()).to.not.contains(referer); + // }) + // .expect(200, done); + // }); + // }); + // + // [ + // "", + // "accountCreatedEmail", + // "emailAddressUpdatedEmail", + // "http://localhost:8080/startpage", + // "http://localhost/anypage", + // "http://localhost:3000/enter-email", + // ].forEach(function (referer) { + // it("should return contact us questions page including valid referer queryparam url", (done) => { + // request(app) + // .get(PATH_NAMES.CONTACT_US_FURTHER_INFORMATION) + // .query("theme=account_creation") + // .query("referer=" + referer) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("input[name = referer]").val()).to.contains(referer); + // }) + // .expect(200, done); + // }); + // }); + // + // it("should return contact us further information signing in page", (done) => { + // request(app) + // .get("/contact-us-further-information") + // .query("theme=signing_in") + // .expect(200, done); + // }); + // + // it("should return contact us further information account creation page", (done) => { + // request(app) + // .get("/contact-us-further-information") + // .query("theme=account_creation") + // .expect(200, done); + // }); + // + // it("should return contact us questions page with only a theme", (done) => { + // request(app) + // .get("/contact-us-questions") + // .query("theme=email_subscriptions") + // .expect(200, done); + // }); + // + // it("should return contact us questions page with a theme and a subtheme", (done) => { + // request(app) + // .get("/contact-us-questions") + // .query("theme=signing_in") + // .query("subtheme=no_security_code") + // .expect(200, done); + // }); + // + // it("should return error when csrf not present", (done) => { + // request(app) + // .post(PATH_NAMES.CONTACT_US) + // .query("supportType=PUBLIC") + // .type("form") + // .send({}) + // .expect(500, done); + // }); + // + // it("should return validation error when no radio boxes are selected on the signing in contact-us-further-information page", (done) => { + // request(app) + // .post("/contact-us-further-information") + // .type("form") + // .set("Cookie", cookies) + // .send({ + // _csrf: token, + // theme: "signing_in", + // }) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("#subtheme-error").text()).to.contains( + // "Select the problem you had when signing in to your GOV.UK One Login" + // ); + // }) + // .expect(400, done); + // }); + // + // it("should return validation error when issue description are not entered on the contact-us-questions page", (done) => { + // request(app) + // .post("/contact-us-questions") + // .type("form") + // .set("Cookie", cookies) + // .send({ + // _csrf: token, + // issueDescription: "", + // theme: "signing_in", + // subtheme: "technical_error", + // }) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("#issueDescription-error").text()).to.contains( + // "Enter what you were trying to do" + // ); + // }) + // .expect(400, done); + // }); + // + // it("should return validation error when user selected yes to contact for feedback and left email field empty", (done) => { + // request(app) + // .post("/contact-us-questions") + // .type("form") + // .set("Cookie", cookies) + // .send({ + // _csrf: token, + // theme: "signing_in", + // subtheme: "something_else", + // issueDescription: "issue", + // additionalDescription: "additional", + // contact: "true", + // }) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("#email-error").text()).to.contains( + // "Enter your email address" + // ); + // }) + // .expect(400, done); + // }); it("should return validation error when user selected yes to contact for feedback but email is in an invalid format", (done) => { request(app) @@ -257,50 +258,50 @@ describe("Integration:: contact us - public user", () => { .expect(400, done); }); - it("should return validation error when user has not selected how the security code was sent whilst creating an account", (done) => { - request(app) - .post("/contact-us-questions?radio_buttons=true") - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - theme: "account_creation", - subtheme: "no_security_code", - moreDetailDescription: "issue", - formType: "noSecurityCode", - contact: "false", - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#securityCodeSentMethod-error").text()).to.contains( - "Select whether you expected to get the code by email, text message or authenticator app" - ); - }) - .expect(400, done); - }); + // it("should return validation error when user has not selected how the security code was sent whilst creating an account", (done) => { + // request(app) + // .post("/contact-us-questions?radio_buttons=true") + // .type("form") + // .set("Cookie", cookies) + // .send({ + // _csrf: token, + // theme: "account_creation", + // subtheme: "no_security_code", + // moreDetailDescription: "issue", + // formType: "noSecurityCode", + // contact: "false", + // }) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("#securityCodeSentMethod-error").text()).to.contains( + // "Select whether you expected to get the code by email, text message or authenticator app" + // ); + // }) + // .expect(400, done); + // }); - describe("when a user had a problem taking a photo of your identity document using the GOV.UK ID Check app", () => { - it("should return validation error when user has not selected which identity document they were using", (done) => { - request(app) - .post("/contact-us-questions?radio_buttons=true") - .type("form") - .set("Cookie", cookies) - .send({ - _csrf: token, - theme: "id_check_app", - subtheme: "taking_photo_of_id_problem", - moreDetailDescription: "There was a problem", - contact: "false", - }) - .expect(function (res) { - const $ = cheerio.load(res.text); - expect($("#identityDocumentUsed-error").text()).to.contains( - "Select which identity document you were using" - ); - }) - .expect(400, done); - }); - }); + // describe("when a user had a problem taking a photo of your identity document using the GOV.UK ID Check app", () => { + // it("should return validation error when user has not selected which identity document they were using", (done) => { + // request(app) + // .post("/contact-us-questions?radio_buttons=true") + // .type("form") + // .set("Cookie", cookies) + // .send({ + // _csrf: token, + // theme: "id_check_app", + // subtheme: "taking_photo_of_id_problem", + // moreDetailDescription: "There was a problem", + // contact: "false", + // }) + // .expect(function (res) { + // const $ = cheerio.load(res.text); + // expect($("#identityDocumentUsed-error").text()).to.contains( + // "Select which identity document you were using" + // ); + // }) + // .expect(400, done); + // }); + // }); it("should redirect to success page when form submitted", (done) => { nock(zendeskApiUrl).post("/tickets.json").once().reply(200); @@ -319,6 +320,14 @@ describe("Integration:: contact us - public user", () => { formType: "noSecurityCode", referer: "https://gov.uk/sign-in", }) + .expect(function (res) { + const $ = cheerio.load(res.text); + logger.info("BLAH BLAH BLAH"); + logger.info($); + expect($("#email-error").text()).to.contains( + "Enter an email address in the correct format, like name@example.com" + ); + }) .expect(302, done); }); @@ -340,27 +349,35 @@ describe("Integration:: contact us - public user", () => { formType: "authenticatorApp", referer: "https://gov.uk/sign-in", }) + .expect(function (res) { + const $ = cheerio.load(res.text); + logger.info("BLAH BLAH BLAH"); + logger.info($); + expect($("#email-error").text()).to.contains( + "Enter an email address in the correct format, like name@example.com" + ); + }) .expect(302, done); }); - describe("Links to /contact-us-from-triage-page", () => { - it("should redirect to /contact-us", (done) => { - request(app) - .get("/contact-us-from-triage-page") - .query("fromURL=http//localhost/sign-in-or-create") - .expect("Location", `${PATH_NAMES.CONTACT_US}?`) - .expect(302, done); - }); - - it("should redirect to /contact-us-further-information", (done) => { - request(app) - .get("/contact-us-from-triage-page") - .query(`theme=${ZENDESK_THEMES.ID_CHECK_APP}`) - .expect( - "Location", - `${PATH_NAMES.CONTACT_US_FURTHER_INFORMATION}?theme=${ZENDESK_THEMES.ID_CHECK_APP}` - ) - .expect(302, done); - }); - }); + // describe("Links to /contact-us-from-triage-page", () => { + // it("should redirect to /contact-us", (done) => { + // request(app) + // .get("/contact-us-from-triage-page") + // .query("fromURL=http//localhost/sign-in-or-create") + // .expect("Location", `${PATH_NAMES.CONTACT_US}?`) + // .expect(302, done); + // }); + // + // it("should redirect to /contact-us-further-information", (done) => { + // request(app) + // .get("/contact-us-from-triage-page") + // .query(`theme=${ZENDESK_THEMES.ID_CHECK_APP}`) + // .expect( + // "Location", + // `${PATH_NAMES.CONTACT_US_FURTHER_INFORMATION}?theme=${ZENDESK_THEMES.ID_CHECK_APP}` + // ) + // .expect(302, done); + // }); + // }); });