1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 |
2x
2x
2x
2x
2x
2x
2x
18x
18x
2x
2x
2x
2x
10x
2x
22x
22x
22x
22x
2x
2x
2x
2x
| /**
* 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 */
"use strict";
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);
});
})();
|