gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
327 lines (309 loc) • 13.1 kB
JavaScript
/**
GPII DB Data Store Tests
Copyright 2016-2019 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/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii"),
jqUnit = fluid.require("node-jqunit", require, "jqUnit");
require("gpii-couchdb-test-harness");
gpii.test.couchdb.loadTestingSupport();
fluid.defaults("gpii.tests.dbDataStore.environment", {
gradeNames: ["gpii.test.couchdb.environment.base"],
databases: {
gpii: {
data: [
"%gpii-db-operation/test/data/clientCredentials.json",
"%gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json",
"%gpii-db-operation/test/data/gpiiAppInstallationClients.json",
"%gpii-db-operation/test/data/gpiiKeys.json",
"%gpii-db-operation/test/data/prefsSafes.json",
"%gpii-universal/testData/dbData/views.json"
]
}
},
components: {
testCaseHolder: {
type: "gpii.tests.dbDataStore.baseTestCaseHolder"
}
},
distributeOptions: {
source: "{that}.options.rawModules",
target: "{that > testCaseHolder}.options.rawModules"
},
mergePolicy: {
rawModules: "noexpand"
}
});
fluid.defaults("gpii.tests.dbDataStore.baseTestCaseHolder", {
gradeNames: ["gpii.test.couchdb.caseHolder"],
events: {
onResponse: null,
onError: null
},
components: {
dbDataStore: {
type: "gpii.dbOperation.dbDataStore",
options: {
dataSourceConfig: {
baseUrl: "http://localhost",
port: "{gpii.tests.dbDataStore.environment}.options.couch.port",
dbName: "gpii"
}
}
}
}
});
gpii.tests.dbDataStore.executeFnAndVerifyResults = function (dbDataStore, fnName, fnArgs, caseHolder) {
var outerPromise = fluid.promise();
dbDataStore[fnName].apply(null, fnArgs).then(
function (results) {
caseHolder.lastSavedId = results.id;
dbDataStore.findById(results.id).then(outerPromise.resolve, outerPromise.reject);
},
outerPromise.reject
);
return outerPromise;
};
gpii.tests.dbDataStore.verifyFetched = function (response, expected, that) {
jqUnit.assertEquals("The fetched document id matches the saved record", that.lastSavedId, response.id);
jqUnit.assertLeftHand("The data is saved successfully", expected, response);
};
gpii.tests.dbDataStore.verifyFetchedGpiiKey = function (response, expected, that) {
// verify the GPII key
var gpiiKey = expected.gpiiKey;
if (gpiiKey) {
jqUnit.assertEquals("The \"id\" value has been set to the provided key", gpiiKey, response.id);
} else {
jqUnit.assertNotUndefined("The \"id\" value has been set to an auto generated key", response.id);
}
// verify other fields
var nonIdFields = fluid.censorKeys(expected, ["gpiiKey"]);
gpii.tests.dbDataStore.verifyFetched(response, nonIdFields, that);
jqUnit.assertEquals("The \"type\" value has been set to default", gpii.dbOperation.docTypes.gpiiKey, response.type);
jqUnit.assertEquals("The \"schemaVersion\" value has been set to default", gpii.dbOperation.schemaVersion, response.schemaVersion);
jqUnit.assertFalse("The \"revoked\" value has been set to false", response.revoked);
jqUnit.assertNull("The \"revokedReason\" value has been set to null", response.revokedReason);
jqUnit.assertNotUndefined("The \"timestampCreated\" value has been created", response.timestampCreated);
jqUnit.assertNull("The \"timestampUpdated\" value has been set to null", response.timestampUpdated);
jqUnit.assertNull("The \"timestampRevoked\" value has been set to null", response.timestampRevoked);
};
gpii.tests.dbDataStore.verifyCreatedPrefsSafe = function (response, expected, that) {
gpii.tests.dbDataStore.verifyFetched(response, expected, that);
jqUnit.assertEquals("The \"type\" value has been set to default", gpii.dbOperation.docTypes.prefsSafe, response.type);
jqUnit.assertEquals("The \"schemaVersion\" value has been set to default", gpii.dbOperation.schemaVersion, response.schemaVersion);
jqUnit.assertEquals("The \"prefsSafeType\" value has been set to default", expected.prefsSafeType, response.prefsSafeType);
jqUnit.assertNotUndefined("The \"timestampCreated\" value has been created", response.timestampCreated);
jqUnit.assertNull("The \"timestampUpdated\" value has been set to null", response.timestampUpdated);
};
gpii.tests.dbDataStore.verifyUpdatedRecord = function (response, expected, that) {
gpii.tests.dbDataStore.verifyFetched(response, expected, that);
jqUnit.assertNotUndefined("The \"timestampUpdated\" value has been created", response.timestampUpdated);
};
gpii.tests.dbDataStore.verifyFetchedGpiiAppInstallationAuthorization = function (response, expected, that) {
gpii.tests.dbDataStore.verifyFetched(response, expected, that);
jqUnit.assertEquals("The \"type\" value has been set to default", gpii.dbOperation.docTypes.gpiiAppInstallationAuthorization, response.type);
jqUnit.assertEquals("The \"schemaVersion\" value has been set to default", gpii.dbOperation.schemaVersion, response.schemaVersion);
jqUnit.assertFalse("The \"revoked\" value has been set to false", response.revoked);
jqUnit.assertNull("The \"revokedReason\" value has been set to null", response.revokedReason);
jqUnit.assertNotUndefined("The \"timestampCreated\" value has been created", response.timestampCreated);
jqUnit.assertNull("The \"timestampRevoked\" value has been set to null", response.timestampRevoked);
};
gpii.tests.dbDataStore.testData = {
gpiiKeyChromehcDefault: {
"id": "chrome_high_contrast",
"type": "gpiiKey",
"schemaVersion": "0.2",
"prefsSafeId": "prefsSafe-1",
"prefsSetId": "gpii-default",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampUpdated": null
},
client1: {
"id": "gpiiAppInstallationClient-1",
"type": "gpiiAppInstallationClient",
"schemaVersion": "0.2",
"name": "AJC-Bakersfield",
"computerType": "public",
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampUpdated": null
},
clientCredential1: {
"id": "clientCredential-1",
"type": "clientCredential",
"schemaVersion": "0.2",
"clientId": "gpiiAppInstallationClient-1",
"oauth2ClientId": "net.gpii.ajc.bakersfield",
"oauth2ClientSecret": "client_secret_ajc_bakersfield",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampRevoked": null
},
findPrefsSafeByGpiiKey_withPrefsSafe: {
"gpiiKey": "chrome_high_contrast",
"gpiiKeyDetails": {
"id": "chrome_high_contrast",
"type": "gpiiKey",
"schemaVersion": "0.2",
"prefsSafeId": "prefsSafe-1",
"prefsSetId": "gpii-default",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampUpdated": null
},
"prefsSafe": {
"id": "prefsSafe-1",
"type": "prefsSafe",
"schemaVersion": "0.2",
"prefsSafeType": "user",
"name": null,
"password": null,
"email": null,
"preferences": {
"flat": {
"contexts": {
"gpii-default": {
"name": "Default preferences",
"preferences": {
"http://registry.gpii.net/common/matchMakerType": "ruleBased",
"http://registry.gpii.net/common/fontSize": 24,
"http://registry.gpii.net/common/foregroundColor": "white",
"http://registry.gpii.net/common/backgroundColor": "black",
"http://registry.gpii.net/common/fontFaceFontName": [
"Comic Sans"
],
"http://registry.gpii.net/common/fontFaceGenericFontFace": "sans serif",
"http://registry.gpii.net/common/magnification": 2
}
}
}
}
},
"timestampCreated": "2017-12-01T18:43:32.889Z",
"timestampUpdated": null
}
},
findPrefsSafeByGpiiKey_noPrefsSafe: {
"gpiiKey": "chrome_high_contrast_dark",
"gpiiKeyDetails": {
"id": "chrome_high_contrast_dark",
"type": "gpiiKey",
"schemaVersion": "0.2",
"prefsSafeId": null,
"prefsSetId": null,
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampUpdated": null
},
"prefsSafe": null
},
findClientByOauth2ClientId: {
"oauth2ClientId": "net.gpii.ajc.bakersfield",
"client": {
"type": "gpiiAppInstallationClient",
"schemaVersion": "0.2",
"name": "AJC-Bakersfield",
"computerType": "public",
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampUpdated": null,
"id": "gpiiAppInstallationClient-1"
},
"clientCredential": {
"type": "clientCredential",
"schemaVersion": "0.2",
"clientId": "gpiiAppInstallationClient-1",
"oauth2ClientId": "net.gpii.ajc.bakersfield",
"oauth2ClientSecret": "client_secret_ajc_bakersfield",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampRevoked": null,
"id": "clientCredential-1"
}
},
gpiiKeyToCreate_noGpiiKey: {
"prefsSafeId": "a-new-prefs-safe-id",
"prefsSetId": "gpii-default"
},
gpiiKeyToCreate_withGpiiKey: {
"gpiiKey": "a-new-gpii-key",
"prefsSafeId": "a-new-prefs-safe-id",
"prefsSetId": "gpii-default"
},
gpiiKeyToUpdate: {
"type": "gpiiKey",
"schemaVersion": "0.2",
"prefsSafeId": "prefsSafe-1",
"prefsSetId": "updated_name",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-05-29T17:54:00.000Z",
"timestampRevoked": "2017-06-29T17:54:00.000Z"
},
prefsSafeToCreate: {
"prefsSafeType": "user",
"name": null,
"password": null,
"email": null,
"preferences": {
"test": "test"
}
},
prefsSafeToUpdate: {
"type": "prefsSafe",
"schemaVersion": "0.2",
"prefsSafeType": "snapset",
"name": "updated_name",
"password": "updated_password",
"email": "updated_email",
"preferences": {
"test": "test"
},
"timestampCreated": "2017-05-29T17:54:00.000Z"
},
gpiiAppInstallationAuthorizationToCreate: {
"clientId": "client-1",
"gpiiKey": "chrome_high_contrast",
"clientCredentialId": "clientCredential-1",
"accessToken": "gpii-app-installation-accessToken-1",
"timestampExpires": "3020-05-29T17:54:00.000Z"
},
findGpiiAppInstallationAuthorizationByAccessToken: {
"accessToken": "gpii-app-installation-accessToken-1",
"clientCredential": {
"type": "clientCredential",
"schemaVersion": "0.2",
"clientId": "gpiiAppInstallationClient-1",
"oauth2ClientId": "net.gpii.ajc.bakersfield",
"oauth2ClientSecret": "client_secret_ajc_bakersfield",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-11-21T18:11:22.101Z",
"timestampRevoked": null,
"id": "clientCredential-1"
},
"authorization": {
"type": "gpiiAppInstallationAuthorization",
"schemaVersion": "0.2",
"clientId": "gpiiAppInstallationClient-1",
"gpiiKey": "chrome_high_contrast",
"clientCredentialId": "clientCredential-1",
"accessToken": "gpii-app-installation-accessToken-1",
"revoked": false,
"revokedReason": null,
"timestampCreated": "2017-05-29T17:54:00.000Z",
"timestampRevoked": null,
"timestampExpires": "3020-05-30T17:54:00.000Z",
"id": "gpiiAppInstallationAuthorization-1"
}
}
};