gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
156 lines (142 loc) • 4.26 kB
JavaScript
/**
* GPII Journal ID Parser Tests
*
* Copyright 2016 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
/* global jqUnit */
;
var fluid = fluid || require("infusion");
(function () {
var gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.tests.journal.idParser");
gpii.tests.journal.idParser.fixtures = [{
toParse: "HEAD",
expected: {
type: "HEAD",
depth: 0
}
}, {
toParse: "HEAD~",
expected: {
type: "HEAD",
depth: 1
}
}, {
toParse: "HEAD~1",
expected: {
type: "HEAD",
depth: 1
}
}, {
toParse: "HEAD~2",
expected: {
type: "HEAD",
depth: 2
}
}, {
toParse: "HEAD~x",
expected: gpii.journal.idFormatError
}, {
toParse: "Unfortunate",
expected: gpii.journal.idFormatError
}, {
toParse: "<2000-01-01",
expected: {
type: "DATE",
before: 1,
date: 946684800000
}
}, {
toParse: ">1997-07-16T12:00:00.155Z",
expected: {
type: "DATE",
before: -1,
date: 869054400155
}
}, {
toParse: ">1997-07-16X12:00:00.155Z",
expected: gpii.journal.idFormatError
}
];
jqUnit.test("Parsing journal ID specifications", function () {
fluid.each(gpii.tests.journal.idParser.fixtures, function (fixture, index) {
var parsed = gpii.journal.parseId(fixture.toParse);
jqUnit.assertDeepEq("Expected result for fixture " + index + ": " + fixture.toParse, fixture.expected, parsed);
});
});
gpii.tests.journal.idParser.journalFiles = [{
id: 1,
date: "2016-07-21T11:10:42.584Z"
}, {
id: 2,
date: "2016-07-20T20:58:52.654Z"
}, {
id: 3,
date: "2016-07-20T20:58:38.942Z"
}, {
id: 4,
date: "2016-07-20T20:57:01.402Z"
}, {
id: 5,
date: "2016-07-20T20:56:41.981Z"
}];
gpii.tests.journal.idParser.fetchFixtures = [{
journalId: "HEAD",
expected: 1
}, {
journalId: "HEAD~",
expected: 2
}, {
journalId: "HEAD~5",
expected: undefined
}, {
journalId: ">2016-07-20T20:58:52.000Z",
expected: 2
}, {
journalId: "<2016-07-20T20:58:52.000Z",
expected: 3
}, {
journalId: ">2000-01-01T00:00:00.000Z",
expected: 5
}, {
journalId: "<2000-01-01T00:00:00.000Z",
expected: undefined
}, {
journalId: ">2020-01-01T00:00:00.000Z",
expected: undefined
}, {
journalId: "<2020-01-01T00:00:00.000Z",
expected: 1
}, {
journalId: ">2016-07-21T11:10:42.584Z",
expected: 1
}, {
journalId: "<2016-07-21T11:10:42.584Z",
expected: 1
}];
jqUnit.test("Journal fetch test", function () {
var journalFiles = fluid.transform(gpii.tests.journal.idParser.journalFiles, function (journalFile) {
return {
id: journalFile.id,
createTime: Date.parse(journalFile.date)
};
});
fluid.each(gpii.tests.journal.idParser.fetchFixtures, function (fixture, index) {
var parsed = gpii.journal.parseId(fixture.journalId);
var fetched = gpii.journal.fetchJournal(journalFiles, parsed);
var fetchedId = fluid.get(fetched, "id");
jqUnit.assertEquals("Expected result for fixture " + index + ": " + fixture.journalId, fixture.expected, fetchedId);
});
});
jqUnit.test("Datestamp to filename formatter", function () {
var date = new Date("2016-07-20T20:58:52.000Z").getTime();
var sanitized = gpii.journal.formatTimestamp(date);
jqUnit.assertEquals("Sanitized datestamp to remove colon characters", "2016-07-20T205852.000Z", sanitized);
});
})();