Rewrites checkVersion and checkVersionNewer in utils-service.js, refines upgradeToVersion
- Adds unit tests that cover all cases. - Adds call to parseVersionString() so we can pass it version string e.g. '1.0.1' - persistence-service.js now also manages JamstashVersion. It is set in localStorage from app.js's constant, and not from the changelog so we don't have to add a version to the changelog to actually do stuff. - persistence-service.js's upgradeToVersion() now only applies newer changesets. This ensures we won't erase users' settings with changesets at every new version, e.g. resetting songSearchType to song every time. - upgradeToVersion() will also notify the user of the upgrade, which was formerly done in settings.js
This commit is contained in:
parent
ae703c1542
commit
fe6c10bc4a
6 changed files with 274 additions and 92 deletions
|
@ -1,5 +1,143 @@
|
|||
describe("utils service", function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
|
||||
});
|
||||
var $rootScope, utils, mockGlobals;
|
||||
beforeEach(function() {
|
||||
module('jamstash.utils', function ($provide) {
|
||||
$provide.value('globals', mockGlobals);
|
||||
});
|
||||
|
||||
inject(function (_utils_, _$rootScope_) {
|
||||
utils = _utils_;
|
||||
$rootScope = _$rootScope_;
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseVersionString() -", function() {
|
||||
it("Given a version string '2.0.1', when I parse it into a version object, then the result will be {major: 2, minor: 0, patch: 1}", function() {
|
||||
var result = utils.parseVersionString('2.0.1');
|
||||
expect(result).toEqual({major: 2, minor: 0, patch: 1});
|
||||
});
|
||||
|
||||
it("Given a random string 'IHtd8EAL9HeLdc', when I parse it into a version object, then the result will be {major: 0, minor: 0, patch: 0}", function() {
|
||||
var result = utils.parseVersionString('IHtd8EAL9HeLdc');
|
||||
expect(result).toEqual({major: 0, minor: 0, patch: 0});
|
||||
});
|
||||
|
||||
it("Given something other than a number, when I parse it into a version object, then the result will be false", function() {
|
||||
var result = utils.parseVersionString(84.1061);
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkVersion() -", function() {
|
||||
var running, required;
|
||||
beforeEach(function() {
|
||||
running = '';
|
||||
required = '';
|
||||
});
|
||||
|
||||
it("Given two version strings '2.0.1' and '1.2.3', when I check the version required, the result will be true", function() {
|
||||
running = '2.0.1';
|
||||
required = '1.2.3';
|
||||
expect(utils.checkVersion(running, required)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version objects {major: 2, minor: 0, patch: 1} and {major: 1, minor: 2, patch: 3}, when I check the version required, the result will be true", function() {
|
||||
running = {
|
||||
major: 2,
|
||||
minor: 0,
|
||||
patch: 1
|
||||
};
|
||||
required = {
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 0
|
||||
};
|
||||
expect(utils.checkVersion(running, required)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.3.0' and '1.2.3', when I check the version required, the result will be true", function() {
|
||||
running = '1.3.0';
|
||||
required = '1.2.3';
|
||||
expect(utils.checkVersion(running, required)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.2.2' and '1.2.3', when I check the version required, the result will be false", function() {
|
||||
running = '1.2.2';
|
||||
required = '1.2.3';
|
||||
expect(utils.checkVersion(running, required)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.2.3' and '1.2.3', when I check the version required, the result will be true", function() {
|
||||
running = '1.2.3';
|
||||
required = '1.2.3';
|
||||
expect(utils.checkVersion(running, required)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two random strings 'wISr91GRXzTsxkx' and 'uSIwvRDp8QJO', when I check the version required, the result will be true", function() {
|
||||
running = 'wISr91GRXzTsxkx';
|
||||
required = 'uSIwvRDp8QJO';
|
||||
expect(utils.checkVersion(running, required)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkVersionNewer() -", function() {
|
||||
var newer, older;
|
||||
beforeEach(function() {
|
||||
newer = '';
|
||||
older = '';
|
||||
});
|
||||
|
||||
it("Given two version strings '2.0.1' and '1.2.3', when I check if the first version is newer, the result will be true", function() {
|
||||
newer = '2.0.1';
|
||||
older = '1.2.3';
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version objects {major: 2, minor: 0, patch: 1} and {major: 1, minor: 2, patch: 3}, when I check if the first version is newer, the result will be true", function() {
|
||||
newer = {
|
||||
major: 2,
|
||||
minor: 0,
|
||||
patch: 1
|
||||
};
|
||||
older = {
|
||||
major: 1,
|
||||
minor: 2,
|
||||
patch: 0
|
||||
};
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.3.0' and '1.2.3', when I check if the first version is newer, the result will be true", function() {
|
||||
newer = '1.3.0';
|
||||
older = '1.2.3';
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.2.2' and '1.2.3', when I check if the first version is newer, the result will be false", function() {
|
||||
newer = '1.2.2';
|
||||
older = '1.2.3';
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.2.3' and '1.2.3', when I check if the first version is newer, the result will be false", function() {
|
||||
newer = '1.2.3';
|
||||
older = '1.2.3';
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("Given two version strings '1.0.1' and '1.0.0', when I check if the first version is newer, the result will be true", function() {
|
||||
newer = '1.0.1';
|
||||
older = '1.0.0';
|
||||
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Given two random strings 'wISr91GRXzTsxkx' and 'uSIwvRDp8QJO', when I check if the first version is newer, the result will be false", function() {
|
||||
newer = 'wISr91GRXzTsxkx';
|
||||
older = 'uSIwvRDp8QJO';
|
||||
expect(utils.checkVersionNewer(newer, older)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue