This commit is contained in:
Lesley Norton 2019-02-01 15:12:31 -06:00
Родитель 4374d49475
Коммит 77494d06ff
3 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -17,6 +17,7 @@ function addBreachesToMockRequest(mockRequest) {
test("home GET without breach renders monitor without breach", () => {
mockRequest.query = { breach: null };
mockRequest = addBreachesToMockRequest(mockRequest);
mockRequest.session = { user: null} ;
const mockResponse = { render: jest.fn() };
home.home(mockRequest, mockResponse);
@ -31,8 +32,11 @@ test("home GET with breach renders monitor with breach", () => {
const testBreach = {Name: "Test"};
mockRequest.query = { breach: testBreach.Name };
mockRequest = addBreachesToMockRequest(mockRequest);
mockRequest.url = "https://www.mozilla.com";
mockRequest.session = { user: null };
const mockResponse = { render: jest.fn() };
home.home(mockRequest, mockResponse);
const mockRenderCallArgs = mockResponse.render.mock.calls[0];

Просмотреть файл

@ -42,13 +42,13 @@ function getMockRequest(userAddLanguages = "en-US,en;q=0.5") {
}
test("confirmed request checks session cookie, calls FXA for token and email, adds new subscriber with signup language, and renders", async () => {
test("confirmed request checks session cookie, calls FXA for token and email, adds new subscriber with signup language, and redirects", async () => {
const testFxAEmail = "fxa-new-user@test.com";
const userAddLanguages = "en-US,en;q=0.5";
EmailUtils.sendEmail = jest.fn();
// Mock the getToken, got, and render calls
const mockRequest = getMockRequest(userAddLanguages);
const mockResponse = { render: jest.fn()};
const mockResponse = { redirect: jest.fn()};
const mockFxAClient = { code : { getToken: jest.fn().mockReturnValueOnce({ accessToken: "testToken"}) } };
got.mockResolvedValue({ body: `{"email": "${testFxAEmail}"}` });
@ -66,9 +66,8 @@ test("confirmed request checks session cookie, calls FXA for token and email, ad
expect(subscribers[0].email).toBe(testFxAEmail);
expect(subscribers[0].signup_language).toBe(userAddLanguages);
const mockRenderCallArgs = mockResponse.render.mock.calls[0];
expect(mockRenderCallArgs[0]).toBe("subpage");
expect(mockRenderCallArgs[1].whichPartial).toBe("subpages/confirm");
const mockRedirectCallArgs = mockResponse.redirect.mock.calls[0];
expect(mockRedirectCallArgs[0]).toBe("/scan/latest_breaches");
});

Просмотреть файл

@ -38,6 +38,7 @@ test("scan POST with hash should render scan with foundBreaches", async () => {
mockRequest.body = { emailHash: sha1(testEmail) };
mockRequest.app = { locals: { breaches: testBreaches } };
mockRequest.session = { user: null };
const mockResponse = { render: jest.fn() };
HIBP.getBreachesForEmail.mockResolvedValue(testFoundBreaches);