Skip to content

Commit

Permalink
feat: Add Initiative and Project Associations (#1213)
Browse files Browse the repository at this point in the history
* feat: association functions

* feat: associated, connected and unconnected queries and functions

* refactor: rename functions to match finalized terminology

* docs: clarify doc string

* refactor: address PR feedback

* refactor: missed a conflict
  • Loading branch information
dbouwman authored Sep 18, 2023
1 parent 5fabc43 commit 7cb0298
Show file tree
Hide file tree
Showing 54 changed files with 1,567 additions and 171 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ENV='qaext'
LOCATION='qaext'
QACREDS_PSW='ADD-THE-REAL-PSW'
QACREDS_USER_PSW='ADD-THE-REAL-PSW'
QA_PORTAL_CREDS_PSW='ADD-THE-REAL-PSW'
121 changes: 57 additions & 64 deletions karma.e2e.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = function(config) {
browserDisconnectTimeout: 120000,
pingTimeout: 1200000,


// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "",

Expand All @@ -23,7 +22,13 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
"packages/*/{src,e2e}/**/*.ts",
{ pattern: 'e2e/test-images/*.jpg', watched: false, included: false, served: true, nocache: false }
{
pattern: "e2e/test-images/*.jpg",
watched: false,
included: false,
served: true,
nocache: false,
},
],

// list of files to exclude
Expand All @@ -33,92 +38,85 @@ module.exports = function(config) {
coverageOptions: {
// Exclude all files - we don't want code coverage on e2e type tests
// also critical so that we can debug in the code
exclude: [
/\.ts$/i,
/fixture*/,
/expected*/
],
exclude: [/\.ts$/i, /fixture*/, /expected*/],
threshold: {
global: {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
excludes: [
'packages/*/examples/**/*.ts',
'packages/*/test/**/*.ts',
'packages/*/e2e/**/*.ts',
]
}
}
"packages/*/examples/**/*.ts",
"packages/*/test/**/*.ts",
"packages/*/e2e/**/*.ts",
],
},
},
},
reports: {
"json": {
"directory": "coverage",
"filename": "coverage.json"
json: {
directory: "coverage",
filename: "coverage.json",
},
"html": "coverage"
html: "coverage",
},
compilerOptions: {
module: "commonjs",
importHelpers: true
importHelpers: true,
},
tsconfig: "./tsconfig.json",
bundlerOptions: {
// validateSyntax: false,
transforms: [
require("karma-typescript-es6-transform")(
{
presets: [
["@babel/preset-env", {
targets: {
chrome: "94"
}
}]
]
}
)
require("karma-typescript-es6-transform")({
presets: [
[
"@babel/preset-env",
{
targets: {
chrome: "94",
},
},
],
],
}),
],
exclude: ["@esri/arcgis-rest-types"],
resolve: {
// karmas resolver cant figure out the symlinked deps from lerna
// so we need to manually alias each package here.
alias: fs
.readdirSync("packages")
.filter(p => p[0] !== ".")
.filter((p) => p[0] !== ".")
.reduce((alias, p) => {
alias[`@esri/templates-${p}`] = `packages/${p}/src/index.ts`;
return alias;
}, {})
}
}
}, {}),
},
},
},

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"packages/*/src/**/*.ts": ["karma-typescript"],
"packages/*/e2e/**/*.ts": ["karma-typescript"],
"packages/*/e2e/**/helpers/config.ts": ["karma-typescript", "env"]
"packages/*/e2e/**/helpers/config.ts": ["karma-typescript", "env"],
},

// Expose this as `window.__env__.QACREDS_PSW
// Used in config files in e2e folders
envPreprocessor: [
"QACREDS_PSW"
],
envPreprocessor: ["QACREDS_PSW", "QACREDS_USER_PSW"],

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// reporters: ["spec", "karma-typescript", "coverage"],
reporters: ["dots", "karma-typescript"],
reporters: ["dots", "karma-typescript"],
coverageReporter: {
// specify a common output directory
dir: 'coverage',
reporters: [
{ type: 'lcov', subdir: 'lcov' }
]
dir: "coverage",
reporters: [{ type: "lcov", subdir: "lcov" }],
},

// web server port
Expand All @@ -136,24 +134,19 @@ module.exports = function(config) {

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'Chrome',
'Edge',
'Firefox'
],
browsers: ["Chrome", "Edge", "Firefox"],
plugins: [
require('karma-env-preprocessor'),
require('@chiragrupani/karma-chromium-edge-launcher'),
require('karma-chrome-launcher'),
require('karma-coverage'),
require('karma-firefox-launcher'),
require('karma-jasmine'),
require('karma-jasmine-diff-reporter'),
require('karma-safari-launcher'),
require('karma-spec-reporter'),
require('karma-typescript'),
require('karma-typescript-es6-transform')

require("karma-env-preprocessor"),
require("@chiragrupani/karma-chromium-edge-launcher"),
require("karma-chrome-launcher"),
require("karma-coverage"),
require("karma-firefox-launcher"),
require("karma-jasmine"),
require("karma-jasmine-diff-reporter"),
require("karma-safari-launcher"),
require("karma-spec-reporter"),
require("karma-typescript"),
require("karma-typescript-es6-transform"),
],

// Continuous Integration mode
Expand All @@ -165,13 +158,13 @@ module.exports = function(config) {
concurrency: Infinity,
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
base: "ChromeHeadless",
flags: ["--no-sandbox"],
},
ChromeDevTools: {
base: 'Chrome',
flags: ['--auto-open-devtools-for-tabs']
}
base: "Chrome",
flags: ["--auto-open-devtools-for-tabs"],
},
},
});
};
132 changes: 132 additions & 0 deletions packages/common/e2e/associations.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {
IHubInitiative,
fetchAcceptedProjects,
fetchHubEntity,
fetchPendingProjects,
} from "../src";
import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
import {
ICreateOutput,
cleanupItems,
createInitiative,
createProjects,
createScopeGroup,
} from "./helpers/metric-fixtures-crud";

const PAIGE_TEST_ITEMS = {
initiative: "14889476c9fd46dbabd694bfd6f65dc4",
projects: [
"1001b7f5150f4b648e61e8c812037921",
"be83e401f9994b93bb2ead0c96c45c9c",
"56e11f847fbb464282eb990cbd139cbd",
"8cc00de75b82414c8c0761aa4300bae3",
"e4852c6189f342399f2af0b69f2558c8",
"68f0231fe334405d8d863c6afedf8a04",
"e5abc74668714e84bb8c56f6c97e5c95",
"e06d9f783bff4e3595843f432a4957b5",
"c49dbaa2ea6045cbb12cefe739f871b0",
"238352acd82d4b55aa59741bba8c269e",
"30fde25db8884a40acff2c39b1e9d075",
"dc46f405197d4111a7584fbdef14c6c9",
],
};

const TEST_ITEMS = {
initiative: "7496421b25db44178bf8993d4eb368a5",
projects: [
"93b53647d84540b9ac4f97891723992c",
"674cec049f5a476ba5417fdf92be0e4c",
"4a25fa2d42b74190b6c2ca0ddabced00",
"85b59fedce9f4d44b8aa47eb580eae01",
"2a6a95d2066e4f3986cccfe81defc45b",
"1bf6055230934e92bca7dfa214507cab",
"e70ad618cb174a0181e792a461d9643d",
"9bcce39151544569a0fe1ea850861df0",
"5cad311f404c4af6be6e64bcf547bf16",
"06c9f201111643179ab8029c91baaa2a",
"980f7687a54e49b29f6ab5cc3903eb5e",
"2d13d504997740c1acb50b2b7a131ee7",
],
};

fdescribe("associations development harness:", () => {
let factory: Artifactory;
const orgName = "hubPremiumAlpha";
beforeAll(() => {
factory = new Artifactory(config);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000;
});
xdescribe("create harness items:", () => {
it("create initative and projects", async () => {
const created: ICreateOutput[] = [];
const ctxMgr = await factory.getContextManager(orgName, "paige");
const configs = [{ key: "Assoc With Metrics", count: 12, groupId: "" }];
try {
for (const cfg of configs) {
// create the group that will be the Initaitive's Project Collection Scope
const group = await createScopeGroup(cfg, ctxMgr.context);
cfg.groupId = group.id;
// create initiative with metric definitions and project collection scope
const initiative = await createInitiative(cfg, ctxMgr.context);
// create projets with metric values, shared to the group
const projects = await createProjects(
cfg,
initiative.id,
ctxMgr.context
);
created.push({
group,
initiative,
projects,
});
}
} finally {
for (const items of created) {
const initiative = items.initiative.toJson();
/* tslint:disable no-console */
console.info(`Initiative: ${initiative.id} Group: ${items.group.id}`);
items.projects.forEach((project) => {
/* tslint:disable no-console */
console.log(`Project: ${project.id}`);
});
// debugger;
// await cleanupItems(items, ctxMgr.context);
}
}
});
});
describe("flex the functions:", () => {
it("search for accepted projects", async () => {
const ctxMgr = await factory.getContextManager(orgName, "admin");
const context = ctxMgr.context;
const entity = (await fetchHubEntity(
"initiative",
TEST_ITEMS.initiative,
context
)) as IHubInitiative;
// debugger;
const projects = await fetchAcceptedProjects(
entity,
context.hubRequestOptions
);
expect(projects.length).toBe(6);
});

it("search for pending projects", async () => {
const ctxMgr = await factory.getContextManager(orgName, "admin");
const context = ctxMgr.context;
const entity = (await fetchHubEntity(
"initiative",
TEST_ITEMS.initiative,
context
)) as IHubInitiative;
const projects = await fetchPendingProjects(
entity,
context.hubRequestOptions
);

expect(projects.length).toBe(6);
});
});
});
20 changes: 15 additions & 5 deletions packages/common/e2e/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@
import { getProp } from "../../src";

let PWD;
let USER_PWD;
if (typeof window === "undefined" && process.env) {
if (!process.env.QACREDS_PSW) {
if (!process.env.QACREDS_PSW || !process.env.QACREDS_USER_PSW) {
throw new Error(
"QACREDS_PSW Could not be read! Please ensure you have a .env file configured! Use the .env-example file and ask others on the team where to get the values!"
"QACREDS_PSW or QACREDS_USER_PSW Could not be read! Please ensure you have a .env file configured! Use the .env-example file and ask others on the team where to get the values!"
);
} else {
PWD = process.env.QACREDS_PSW;
USER_PWD = process.env.QACREDS_USER_PSW;
}
} else {
if (!getProp(window, "__env__.QACREDS_PSW")) {
if (
!getProp(window, "__env__.QACREDS_PSW") ||
!getProp(window, "__env__.QACREDS_USER_PSW")
) {
throw new Error(
"QACREDS_PSW Could not be read! Please ensure you have a .env file configured! Use the .env-example file and ask others on the team where to get the values!"
"QACREDS_PSW or QACREDS_USER_PSW Could not be read! Please ensure you have a .env file configured! Use the .env-example file and ask others on the team where to get the values!"
);
} else {
PWD = getProp(window, "__env__.QACREDS_PSW");
USER_PWD = getProp(window, "__env__.QACREDS_USER_PSW");
}
}

Expand Down Expand Up @@ -58,13 +64,17 @@ const config = {
orgShort: "qa-pre-a-hub",
orgUrl: "https://qa-pre-a-hub.mapsqa.arcgis.com",
admin: {
username: "paige_pa",
username: "e2e_pre_a_pub_admin",
password: PWD,
},
user: {
username: "e2e_pre_a_pub_publisher",
password: PWD,
},
paige: {
username: "paige_pa",
password: USER_PWD,
},
fixtures: {
items: {
sitePageMapViewsLayersTable: "5741debb4bd9476e9511035126c7edb6",
Expand Down
Loading

0 comments on commit 7cb0298

Please sign in to comment.