forked from jenkinsci/build-monitor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As per Reynald Borer's suggestion, Build Monitor now uses YAHOO.util.…
…Cookie object instead of AngularJS cookie service and is able to set cookies that live longer than a browser session (about a year longer, to be precise). This closes jenkinsci#10 - thanks @rborer !
- Loading branch information
Showing
11 changed files
with
223 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
'use strict'; | ||
|
||
describe('buildMonitor', function () { | ||
describe('buildMonitor.services', function () { | ||
describe('cookieJar', function () { | ||
|
||
var services, | ||
YahooCookie = YAHOO.util.Cookie, | ||
mockedCookie, // YAHOO.util.Cookie backend used by the cookieJar | ||
|
||
NAME = 'numberOfColumns', | ||
VALUE = 3, | ||
DEFAULT_VALUE = 1; | ||
|
||
beforeEach(function () { | ||
services = angular.module('buildMonitor.services'); | ||
|
||
mockedCookie = sinon.mock(YahooCookie); | ||
|
||
module('buildMonitor.services', function ($provide) { | ||
$provide.value('YahooCookie', YahooCookie); | ||
}); | ||
}); | ||
|
||
describe('default configuration', function() { | ||
|
||
it('returns "undefined" if requested value couldn\'t be found in a cookie and no defaults are provided', inject(function (cookieJar) { | ||
expect(cookieJar.get('aCookieThatDoesNotExist')).toBeUndefined(); | ||
})); | ||
|
||
it('returns default value if the one requested couldn\'t be found in a cookie', inject(function (cookieJar) { | ||
expect(cookieJar.get('aCookieThatDoesNotExist', DEFAULT_VALUE)).toBe(DEFAULT_VALUE); | ||
})); | ||
|
||
it('allows for a value to be persisted and then retrieved', inject(function (cookieJar) { | ||
mockedCookie.expects("set").withArgs(NAME, VALUE); | ||
mockedCookie.expects("get").withArgs(NAME).returns(VALUE); | ||
|
||
|
||
cookieJar.put(NAME, VALUE); | ||
|
||
expect(cookieJar.get(NAME)).toBe(VALUE); | ||
|
||
mockedCookie.verify() | ||
})); | ||
|
||
it('should use cookies that expire at the end of the session', inject(function (cookieJar) { | ||
var noExpiryDateSpecified = {}; | ||
|
||
mockedCookie.expects("set").withArgs(NAME, VALUE, noExpiryDateSpecified); | ||
|
||
|
||
cookieJar.put(NAME, VALUE); | ||
|
||
mockedCookie.verify(); | ||
})); | ||
}); | ||
|
||
describe('custom label', function () { | ||
|
||
var COOKIE_JAR_LABEL = 'chocolateChipCookies'; | ||
|
||
beforeEach(function () { | ||
services.config(function(cookieJarProvider) { | ||
cookieJarProvider.describe({ | ||
label: COOKIE_JAR_LABEL | ||
}); | ||
}); | ||
}); | ||
|
||
it('should prefix each cookie with a label', inject(function (cookieJar) { | ||
mockedCookie.expects("set").withArgs(prefixed(NAME), VALUE); | ||
mockedCookie.expects("get").withArgs(prefixed(NAME)); | ||
|
||
|
||
cookieJar.put(NAME, VALUE); | ||
cookieJar.get(NAME); | ||
|
||
mockedCookie.verify(); | ||
})); | ||
|
||
afterEach(function() { | ||
mockedCookie.restore(); | ||
}); | ||
|
||
function prefixed(name) { | ||
return COOKIE_JAR_LABEL + '.' + name; | ||
}; | ||
}); | ||
|
||
describe('custom shelf life', function() { | ||
|
||
var SHELF_LIFE_IN_DAYS = 7; | ||
|
||
beforeEach(function () { | ||
|
||
services.config(function(cookieJarProvider) { | ||
cookieJarProvider.describe({ | ||
shelfLife: SHELF_LIFE_IN_DAYS | ||
}); | ||
}); | ||
}); | ||
|
||
it('should use cookies that expire when specified', inject(function (cookieJar) { | ||
mockedCookie.expects("set").withArgs(NAME, VALUE, { | ||
expires: dateIn(SHELF_LIFE_IN_DAYS)} | ||
); | ||
|
||
cookieJar.put(NAME, VALUE); | ||
|
||
mockedCookie.verify(); | ||
})); | ||
|
||
afterEach(function() { | ||
mockedCookie.restore(); | ||
}); | ||
|
||
function dateIn(days) { | ||
return new Date(+new Date() + (days * 24 * 3600 * 1000)); | ||
}; | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.