Skip to content

Commit

Permalink
create separate catalog for each project + update ermrestdatautils
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH committed Sep 23, 2023
1 parent 97a5fbe commit 61e0c71
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 129 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
timeout-minutes: 120
steps:
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: chaise
- name: Setup the system
Expand Down Expand Up @@ -56,10 +56,6 @@ jobs:
sudo pip3 install globus_sdk
sudo pip3 install psycopg2-binary
sudo pip3 install oauth2client
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install webauthn
run: |
sudo useradd -m -r webauthn
Expand Down
2 changes: 2 additions & 0 deletions docs/dev-docs/e2e-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ TODO

```
page.pause();
npx playwright test --config CONFIG_LOC --project=NAME_OF_PROEJECT --debug
```

## Writing test
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"ui"
],
"devDependencies": {
"@isrd-isi-edu/ermrest-data-utils": "0.0.2",
"@isrd-isi-edu/ermrest-data-utils": "0.0.3",
"@playwright/test": "^1.34.2",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
Expand Down
32 changes: 32 additions & 0 deletions test/playwright/locators/record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { makeSafeIdAttr } from '@isrd-isi-edu/chaise/src/utils/string-utils';
import { Locator, Page } from '@playwright/test';

export default class RecordLocators {
static async waitForRecordPageReady(page: Page) {
await RecordLocators.getEntityTitleElement(page).waitFor({ state: 'visible' });
await RecordLocators.getMainSectionTable(page).waitFor({ state: 'visible' });
await RecordLocators.getRelatedSectionSpinner(page).waitFor({ state: 'detached' })
}

static getEntityTitleElement(page: Page): Locator {
return page.locator('.entity-title');
}

static getMainSectionTable(page: Page): Locator {
return page.locator('.record-main-section-table');
}

static getRelatedSectionSpinner(page: Page): Locator {
return page.locator('.related-section-spinner');
}

static getRelatedTableAccordion(page: Page, displayname: string): Locator {
displayname = makeSafeIdAttr(displayname);
return page.locator(`#rt-heading-${displayname}`);
}

static getRelatedTableAccordionContent(page: Page, displayname: string): Locator {
const acc = RecordLocators.getRelatedTableAccordion(page, displayname);
return acc.locator('.accordion-collapse');
}
}
6 changes: 3 additions & 3 deletions test/playwright/setup/playwright.configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';
import os from 'os';

import { TestOptions } from '@isrd-isi-edu/chaise/test/playwright/setup/playwright.model';
import { STORAGE_STATE } from '@isrd-isi-edu/chaise/test/playwright/setup/playwright.parameters';
import { STORAGE_STATE, PRESET_PROJECT_NAME } from '@isrd-isi-edu/chaise/test/playwright/setup/playwright.parameters';

const getConfig = (options: TestOptions) => {

Expand Down Expand Up @@ -39,7 +39,7 @@ const getConfig = (options: TestOptions) => {
retries: 0,

// Opt out of parallel tests on CI.
workers: process.env.CI ? 1 : undefined,
// workers: process.env.CI ? 1 : undefined,

// Reporter to use
reporter: process.env.CI ? [
Expand All @@ -63,7 +63,7 @@ const getConfig = (options: TestOptions) => {
// Configure projects for major browsers.
projects: [
{
name: 'pretest',
name: PRESET_PROJECT_NAME,
testDir: __dirname,
testMatch: 'playwright.pretest.ts'
},
Expand Down
71 changes: 30 additions & 41 deletions test/playwright/setup/playwright.import.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,31 @@
import axios from 'axios';

import { getCatalogID } from '@isrd-isi-edu/chaise/test/playwright/setup/playwright.parameters';
import { isObjectAndNotNull } from '@isrd-isi-edu/chaise/src/utils/type-utils';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const ermrestUtils = require('@isrd-isi-edu/ermrest-data-utils');


export async function setupCatalog(schemaConfigurations: any) {
/**
* create a catalog object based on the given setup object
* Resolved promise returns the created rows and the id of catalog.
*/
export async function setupCatalog(setup: { catalog: any, schemas: any }): Promise<{ entities: any, catalogId: string }> {
return new Promise((resolve, reject) => {

// merge all the schema configurations
const catalog: any = {}, schemas: any = {};

schemaConfigurations.forEach((config: any) => {
// copy annotations and ACLs over to the submitted catalog object
if (config.catalog && typeof config.catalog === 'object') {
if (!('acls' in config.catalog)) {
config.catalog['acls'] = { 'select': ['*'] };
}

// if empty object, this loop is skipped
for (const prop in config.catalog) {
// if property is set already
if (catalog[prop]) {
console.log(`${prop} is already defined on catalog object, overriding previously set value with new one`);
}
catalog[prop] = config.catalog[prop];
}
}

schemas[config.schema.name] = {
path: config.schema.path
};

if (config.entities) {
schemas[config.schema.name].entities = config.entities.path;
}
});

// create the settings based on the acceptable strucutre.
// please refer to ermest data utils documentation for the strucutre
const settings = {
url: process.env.ERMREST_URL,
authCookie: process.env.AUTH_COOKIE,
setup: { catalog, schemas }
setup: setup
};

// NOTE do we want ot allow this?
// reuse the same catalogid
// if (catalogId) settings.setup.catalog.id = catalogId;

axios.get(process.env.ERMREST_URL!).then((res) => {
return ermrestUtils.createSchemasAndEntities(settings);
}).then(function (data) {
ermrestUtils.createSchemasAndEntities(settings).then(function (data: any) {
const entities: any = {};

if (data.schemas) {
Expand All @@ -69,20 +44,20 @@ export async function setupCatalog(schemaConfigurations: any) {
console.log('Attached entities for the schemas');
}
resolve({ entities: entities, catalogId: data.catalogId });
}).catch(function (err) {
}).catch(function (err: any) {
console.log('error while trying to create model and data:');
console.log(err);
reject(err);
});

});

}

/**
* remove a given catalog
*/
export async function removeCatalog(catalogId: string) {
return new Promise(async (resolve, reject) => {
try {
console.log('remove catalog called!');
await ermrestUtils.tear({
// NOTE this setup is needed by ermrest-data-utils
// we should refactor ermrest-data-utils to not need this
Expand All @@ -93,8 +68,6 @@ export async function removeCatalog(catalogId: string) {
catalogId: catalogId,
authCookie: process.env.AUTH_COOKIE
});

console.log(`catalog ${catalogId} removed.`);
resolve(true);
} catch (exp) {
console.log(`Unable to remove catalog ${catalogId}`);
Expand All @@ -103,6 +76,22 @@ export async function removeCatalog(catalogId: string) {
});
}

/**
* Remove all the catalogs based on the env variable
*/
export async function removeAllCatalogs() {
const catalogIds = getCatalogID();
if (isObjectAndNotNull(catalogIds)) {
for (const p in catalogIds) {
await removeCatalog(catalogIds[p]);
console.log(`Catalog deleted with id ${catalogIds[p]} for project ${p}`);
}
} else {
console.log('Catalog information is missing (either not created or invalid env variable).')
}
return true;
}


/**
* Delete the given list of namespaces
Expand Down
35 changes: 32 additions & 3 deletions test/playwright/setup/playwright.parameters.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
import { isObjectAndNotNull } from '@isrd-isi-edu/chaise/src/utils/type-utils';
import { resolve } from 'path';

export const ERMREST_URL = process.env.ERMREST_URL;

/**
* return the catalog created for tests
* return the catalog created for tests.
*
* YOU MUST CALL THIS WITH A PROJECT NAME IF YOU WANT TO GET THE STRING RESULT
*
* (populated during setup)
*/
export const getCatalogID = () : string => {
return process.env.CATALOG_ID!;
export const getCatalogID = (projectName?: string, dontLogError?: boolean) : string | any | null => {
try {
const obj = JSON.parse(process.env.CATALOG_ID!);
if (!isObjectAndNotNull(obj) || (projectName && !obj[projectName])) {
throw new Error('');
}
return projectName ? obj[projectName] : obj;
} catch (exp) {
if (!dontLogError) {
console.error(exp);
console.log('existing CATALOG_ID env variable value is not valid.');
}
}

return null;
}

export const setCatalogID = (projectName: string, catalogId: string) => {
let curr = getCatalogID(undefined, true);
if (isObjectAndNotNull(curr)) {
curr[projectName] = catalogId;
} else {
curr = {};
curr[projectName] = catalogId;
}
process.env.CATALOG_ID = JSON.stringify(curr);
}


Expand All @@ -23,6 +51,7 @@ export const getCatalogID = () : string => {
*/
export const ENTITIES_PATH = 'entities.json';

export const PRESET_PROJECT_NAME = 'pretest';

/**
* return the session object for the main user (catalog owner).
Expand Down
Loading

0 comments on commit 61e0c71

Please sign in to comment.