Skip to content

Commit

Permalink
CPS-562: Create data
Browse files Browse the repository at this point in the history
  • Loading branch information
deb1990 committed May 5, 2021
1 parent 0b3e2ad commit 7950a8e
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 171 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@types/gulp": "^4.0.8",
"@types/jest": "^26.0.23",
"@types/jest-cli": "^24.3.0",
"@types/lodash": "^4.14.168",
"@types/mysql": "^2.15.18",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"ansi-colors": "^4.1.1",
Expand All @@ -31,6 +32,7 @@
"jest-cli": "^26.6.3",
"jest-playwright-preset": "^1.5.2",
"lint-staged": "^10.5.4",
"lodash": "^4.17.21",
"mysql": "^2.18.1",
"playwright": "^1.10.0",
"playwright-chromium": "^1.10.0",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/base/manage-entity.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page, Response } from 'playwright';
import BrowserService from '../../services/utils/browser.service';
import Configs from '../../services/utils/configs';
import CiviApiService from '../../services/utils/cv-api.service';
import cvApiBatch from '../../services/utils/cv-api.service';

/**
* Manage Entity Page
Expand Down Expand Up @@ -42,11 +42,11 @@ export abstract class ManageEntity {
*/
private getCaseTypeCategoryValue (): number {
// implement a caching service
const caseTypeCategoryValue = CiviApiService('OptionValue', 'get', {
const caseTypeCategoryValue = cvApiBatch([['OptionValue', 'get', {
sequential: 1,
option_group_id: 'case_type_categories',
name: this.caseTypeCategory
}).values[0].value;
}]])[0].values[0].value;

return caseTypeCategoryValue;
}
Expand Down
52 changes: 0 additions & 52 deletions src/services/data/database.service.ts

This file was deleted.

53 changes: 53 additions & 0 deletions src/services/entities/base-entity.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import cvApiBatch from '../utils/cv-api.service';

/**
* Base Entity Service
*/
export default class BaseEntityService {
entityName: string;
entityIds: string[];

/**
* @param {string} entityName name of the entity
*/
constructor (entityName: string) {
this.entityName = entityName;
}

/**
* Create Entity.
*
* @param {any} params parameters
* @returns {object[]} created entities
*/
create (params: any[]): object[] {
this.entityIds = [];

const apiCalls = params.map((param): [string, string, object] => {
return [this.entityName, 'create', param];
});

const apiReturnValue = cvApiBatch(apiCalls).map((caseType) => {
return caseType.values[0];
});

this.entityIds = apiReturnValue.map((caseType) => {
return caseType.id;
});

return apiReturnValue;
}

/**
* Cleanup Entities created by this instance of the class.
*/
cleanUp (): void {
const apiCalls = this.entityIds.map((entityId): [string, string, object] => {
return [this.entityName, 'delete', { id: entityId }];
});

cvApiBatch(apiCalls);

this.entityIds = [];
}
}
13 changes: 13 additions & 0 deletions src/services/entities/case-type.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import BaseEntityService from './base-entity.service';

/**
* Case Entity Service
*/
export default class CaseTypeService extends BaseEntityService {
/**
* Constructor.
*/
constructor () {
super('CaseType');
}
}
13 changes: 13 additions & 0 deletions src/services/entities/case.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import BaseEntityService from './base-entity.service';

/**
* Case Entity Service
*/
export default class CaseService extends BaseEntityService {
/**
* Constructor.
*/
constructor () {
super('Case');
}
}
2 changes: 1 addition & 1 deletion src/services/utils/browser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class BrowserService {
* @param {string} roleName role name
* @returns {Promise<void>}
*/
async loadCookiesFor (roleName: string): Promise<void> {
async loginUsingCookiesAs (roleName: string): Promise<void> {
let cookies: Cookie[] = [];
const cookiePath = Configs.getCookiePathFor(roleName);

Expand Down
18 changes: 2 additions & 16 deletions src/services/utils/cv-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ import Configs from './configs';
import CiviApiResponse from '../interfaces/civi-response.interface';
import UserRole from '../role/user-role.service';

export default cvApi;
/**
* Executes a single call to the `cv api` service and returns the response
* in JSON format.
*
* @param {string} entityName the name of the entity to run the query on.
* @param {string} action the entity action.
* @param {object} queryData the data to pass to the entity action.
* @returns {CiviApiResponse} the result from the entity action call.
*/
function cvApi (entityName: string, action: string, queryData: object): CiviApiResponse {
const queryResponse = cvApiBatch([[entityName, action, queryData]]);

return queryResponse[0];
}
export default cvApiBatch;

/**
* Executes multi calls to the `cv api` service and returns the response from
Expand All @@ -26,7 +12,7 @@ function cvApi (entityName: string, action: string, queryData: object): CiviApiR
* @param {Array<[string, string, object]>} queriesData a list of queries to pass to the `cv api:batch` service.
* @returns {any[]} response from the cv api.
*/
function cvApiBatch (queriesData: Array<[string, string, object]>): any[] {
function cvApiBatch (queriesData: Array<[string, string, object]>): CiviApiResponse[] {
const config = Configs.getSiteConfig();
const cmd = `echo '${JSON.stringify(queriesData)}' | cv api:batch -U ${UserRole.getRoleName('admin')}`;
const responses = JSON.parse(execSync(jsonEscape(cmd), { cwd: config.root }).toString());
Expand Down
41 changes: 0 additions & 41 deletions tests/awards/case_user.manage-applications.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Page } from 'playwright';
import BrowserService from '../../src/services/utils/browser.service';
import { ManageApplications } from '../../src/pages/awards/manage-applications.page';
import DatabaseService from '../../src/services/data/database.service';
import BrowserService from '../../../src/services/utils/browser.service';
import { ManageApplications } from '../../../src/pages/awards/manage-applications.page';

describe('Manage Applications', function () {
describe('Award Page Title', function () {
let page: Page;
let manageApplications: ManageApplications;
const browser = new BrowserService();
Expand All @@ -17,20 +16,18 @@ describe('Manage Applications', function () {
});

beforeEach(async () => {
await DatabaseService.startTransaction();
page = await browser.newPage();

manageApplications = new ManageApplications(browser);
});

afterEach(async () => {
await page.close();
await DatabaseService.rollbackTransaction();
});

describe('on navigate', function () {
describe('as admin user', function () {
beforeEach(async () => {
await browser.loadCookiesFor('admin');
await browser.loginUsingCookiesAs('admin');
await manageApplications.navigate(page);
await manageApplications.waitForPageLoad(page);
});
Expand All @@ -39,4 +36,15 @@ describe('Manage Applications', function () {
expect(await page.title()).toBe(manageApplications.getPageTitle());
});
});

describe('as case user', function () {
beforeEach(async () => {
await browser.loginUsingCookiesAs('case_user');
await manageApplications.navigate(page);
});

it('should not have access to manage applications page', async () => {
expect(await page.title()).not.toBe(manageApplications.getPageTitle());
});
});
});
42 changes: 0 additions & 42 deletions tests/cases/admin.manage-cases.spec.ts

This file was deleted.

Loading

0 comments on commit 7950a8e

Please sign in to comment.