This repository was archived by the owner on Feb 12, 2025. It is now read-only.
forked from javihernandez/universal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPouchTestCaseHolder.js
More file actions
118 lines (107 loc) · 3.86 KB
/
PouchTestCaseHolder.js
File metadata and controls
118 lines (107 loc) · 3.86 KB
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
/*!
GPII PouchDB testing support
Copyright 2016 OCAD University
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/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");
require("gpii-pouchdb");
gpii.pouch.loadTestingSupport();
fluid.defaults("gpii.test.pouch.pouchTestCaseHolder", {
gradeNames: ["fluid.component"],
distributeOptions: [
{
source: "{that}.options.pouchConfig",
target: "{that gpii.pouch.express}.options"
},
{
record: {
"{testCaseHolder}.events.onCleanup": "{that}.events.onCleanup.fire"
},
target: "{that gpii.pouch.express}.options.listeners"
},
{
record: {
"onCleanupComplete.escalate": "{testCaseHolder}.events.onCleanupComplete.fire"
},
target: "{that gpii.pouch.express}.options.listeners"
}
],
pouchConfig: {
databases: {
gpii: {
data: [
"%gpii-universal/tests/data/dbData/clientCredentials.json",
"%gpii-universal/tests/data/dbData/gpiiAppInstallationClients.json",
"%gpii-universal/tests/data/dbData/gpiiKeys.json",
"%gpii-universal/build/tests/dbData/gpiiKeys.json",
"%gpii-universal/build/tests/dbData/prefsSafes.json",
"%gpii-universal/build/dbData/user/gpiiKeys.json",
"%gpii-universal/build/dbData/user/prefsSafes.json",
"%gpii-universal/testData/dbData/views.json"
]
}
}
},
events: {
constructFixtures: null,
onPouchHarnessReady: null,
onFixturesConstructed: {
events: {
onPouchHarnessReady: "onPouchHarnessReady"
}
},
onCleanup: null,
onCleanupComplete: null
},
components: {
pouchHarness: {
type: "gpii.pouch.harness",
createOnEvent: "constructFixtures",
options: {
port: 8058, // TODO: Use gpii-pouch port from configuration
listeners: {
"onReady.escalate": "{testCaseHolder}.events.onPouchHarnessReady.fire"
}
}
}
}
});
gpii.test.pouch.constructFixturesSequence = [
{
func: "{testCaseHolder}.events.constructFixtures.fire"
},
{
event: "{testCaseHolder}.events.onFixturesConstructed",
listener: "fluid.identity"
}
];
gpii.test.pouch.cleanUpDB = [
{
func: "{testCaseHolder}.events.onCleanup.fire"
},
{
event: "{testCaseHolder}.events.onCleanupComplete",
listener: "fluid.identity"
}
];
// Add following steps to the test sequence:
// 1. wait for the completion of the pouchDB construction at the start of the test sequence;
// 2. clean up the pouchDB at the end of the test sequence.
gpii.test.pouch.addConstructFixturesToSequence = function (sequence) {
sequence.unshift.apply(sequence, gpii.test.pouch.constructFixturesSequence);
return sequence.concat(gpii.test.pouch.cleanUpDB);
};
// Add the pouchDB infrastruture to a test definition. This infrastruture starts a pouchDB instance, load test data
// into the pouchDB and clean up the pouchDB when the execution of the test completes.
gpii.test.pouch.addPouchFixturesToTestDef = function (testDef) {
var pouchTestCaseHolder = testDef.pouchTestCaseHolder || "gpii.test.pouch.pouchTestCaseHolder";
testDef.gradeNames = fluid.makeArray(testDef.gradeNames);
testDef.gradeNames.push(pouchTestCaseHolder);
testDef.sequence = gpii.test.pouch.addConstructFixturesToSequence(testDef.sequence);
return testDef;
};