Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit fb39036

Browse files
author
Parth Shah
committed
adding unit tests
1 parent 3751d9f commit fb39036

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

app/services/helpers.service.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165

166166
function redirectPostLogin(nextParam) {
167167
// make sure domain is topcoder | dev | qa
168+
nextParam = decodeURIComponent(nextParam);
168169
var re1 = /^(\w+\.)*topcoder(-\w+)*\.com/;
169170
var re2 = /^\/\w+/;
170171

@@ -173,6 +174,7 @@
173174
} else if (re2.test(nextParam)) {
174175
$location.url(nextParam);
175176
} else {
177+
console.log($state);
176178
$state.go('dashboard');
177179
}
178180
}

app/services/helpers.service.spec.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ describe('Helper Service', function() {
66
href: "/"
77
}
88
};
9+
var fakeLocation = {
10+
url: function(param) {
11+
return;
12+
}
13+
};
14+
sinon.spy(fakeLocation, "url");
15+
var fakeState = {
16+
go: function(name, params) {return;}
17+
};
18+
sinon.spy(fakeState, "go");
919

1020
beforeEach(function() {
11-
bard.appModule('tc.services', function($provide) {
21+
module('tc.services', function($provide) {
1222
$provide.value('$window', fakeWindow);
23+
$provide.value('$state', fakeState);
24+
$provide.value('$location', fakeLocation);
1325
});
1426

15-
bard.inject(this, 'Helpers');
27+
bard.inject(this, 'Helpers', '$state', '$location');
1628
});
1729

1830
describe("isEmail()", function() {
@@ -30,5 +42,15 @@ describe('Helper Service', function() {
3042
Helpers.redirectPostLogin(encodeURIComponent("www.topcoder-dev.com"));
3143
expect(fakeWindow.location.href).to.equal("www.topcoder-dev.com");
3244
});
45+
46+
it("should redirect to the next param", function() {
47+
Helpers.redirectPostLogin(encodeURIComponent("www.google.com"));
48+
expect($state.go).to.have.been.calledWith("dashboard");
49+
});
50+
51+
it("should redirect to the next param", function() {
52+
Helpers.redirectPostLogin(encodeURIComponent("/members/test1/"));
53+
expect($location.url).to.have.been.calledWith("/members/test1/");
54+
});
3355
});
3456
});

0 commit comments

Comments
 (0)