Skip to content

Commit

Permalink
Fix transaction bug introduced in 8f1f835
Browse files Browse the repository at this point in the history
Attempting to refactor the transaction detection logic, I inverted the
match (returning true if inside a transaction URL, not false if *not*
inside a transaction URL) but forgot to invert the if statement to "OR"
from "AND".

This commit fixes that, and adds some tests to ensure the mistake can't
happen again.
  • Loading branch information
kalleth committed Jul 22, 2016
1 parent 05c2625 commit 9558145
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
},

userCompletedTransaction: function() {
var currentURL = window.location.pathname;
var path = userSurveys.currentPath();

function stringContains(str, substr) {
return str.indexOf(substr) > -1;
}

if (stringContains(currentURL, "/done") &&
stringContains(currentURL, "/transaction-finished") &&
stringContains(currentURL, "/driving-transaction-finished")) {
if (stringContains(path, "/done") ||
stringContains(path, "/transaction-finished") ||
stringContains(path, "/driving-transaction-finished")) {
return true;
}
},
Expand Down Expand Up @@ -147,7 +147,8 @@
return "govuk_" + cookieStub;
},

currentTime: function() { return new Date().getTime(); }
currentTime: function() { return new Date().getTime(); },
currentPath: function() { return window.location.pathname; }
};

root.GOVUK.userSurveys = userSurveys;
Expand Down
22 changes: 22 additions & 0 deletions spec/javascripts/surveys-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ describe("Surveys", function() {
});
});

describe("userCompletedTransaction", function() {
it("normally returns false", function() {
spyOn(surveys, 'currentPath').and.returnValue('/');
expect(surveys.userCompletedTransaction()).toBeFalsy();
});

it("returns true when /done", function() {
spyOn(surveys, 'currentPath').and.returnValue('/done');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});

it("returns true when /transaction-finished", function() {
spyOn(surveys, 'currentPath').and.returnValue('/transaction-finished');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});

it("returns true when /driving-transaction-finished", function() {
spyOn(surveys, 'currentPath').and.returnValue('/driving-transaction-finished');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});
});

describe("Event handlers", function () {
beforeEach(function() {
surveys.displaySurvey(defaultSurvey);
Expand Down

0 comments on commit 9558145

Please sign in to comment.