Skip to content

Commit

Permalink
let's see if this works
Browse files Browse the repository at this point in the history
  • Loading branch information
anissa-agahchen committed Apr 19, 2022
1 parent a1c59bd commit 2e17e22
Show file tree
Hide file tree
Showing 35 changed files with 314 additions and 2,655 deletions.
79 changes: 1 addition & 78 deletions api/src/models/public/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,7 @@
import { expect } from 'chai';
import { COMPLETION_STATUS } from '../../constants/status';
import { GetPublicCoordinatorData, GetPublicProjectData } from './project';
import { GetPublicCoordinatorData } from './project';
import { describe } from 'mocha';

describe('GetPublicProjectData', () => {
describe('No values provided', () => {
let data: GetPublicProjectData;

before(() => {
data = new GetPublicProjectData();
});

it('sets name', () => {
expect(data.project_name).to.equal('');
});

it('sets type', () => {
expect(data.project_type).to.equal('');
});

it('sets project_activities', () => {
expect(data.project_activities).to.eql([]);
});

it('sets start_date', () => {
expect(data.start_date).to.equal('');
});

it('sets end_date', () => {
expect(data.end_date).to.equal('');
});

it('sets completion_status', () => {
expect(data.completion_status).to.equal(COMPLETION_STATUS.ACTIVE);
});
});

describe('all values provided', () => {
const projectData = {
name: 'project name',
type: 'type',
start_date: '2020-04-20T07:00:00.000Z',
end_date: '2020-05-20T07:00:00.000Z',
revision_count: 1
};

const activityData = [{ name: 'activity1' }, { name: 'activity2' }];

let data: GetPublicProjectData;

before(() => {
data = new GetPublicProjectData(projectData, activityData);
});

it('sets name', () => {
expect(data.project_name).to.equal(projectData.name);
});

it('sets type', () => {
expect(data.project_type).to.equal(projectData.type);
});

it('sets project_activities', () => {
expect(data.project_activities).to.eql(['activity1', 'activity2']);
});

it('sets start_date', () => {
expect(data.start_date).to.equal('2020-04-20T07:00:00.000Z');
});

it('sets end_date', () => {
expect(data.end_date).to.equal('2020-05-20T07:00:00.000Z');
});

it('sets completion_status', () => {
expect(data.completion_status).to.equal(COMPLETION_STATUS.COMPLETED);
});
});
});

describe('GetPublicCoordinatorData', () => {
describe('No values provided', () => {
let projectCoordinatorData: GetPublicCoordinatorData;
Expand Down
37 changes: 0 additions & 37 deletions api/src/models/public/project.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
import { COMPLETION_STATUS } from '../../constants/status';
import moment from 'moment';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('models/public/project');

/**
* Pre-processes GET /projects/{id} public (published) project data
*
* @export
* @class GetPublicProjectData
*/
export class GetPublicProjectData {
project_name: string;
project_type: string;
project_activities: string[];
start_date: string;
end_date: string;
comments: string;
completion_status: string;
publish_date: string;

constructor(projectData?: any, activityData?: any[]) {
defaultLog.debug({ label: 'GetPublicProjectData', message: 'params', projectData, activityData });

this.project_name = projectData?.name || '';
this.project_type = projectData?.type || '';
this.project_activities = (activityData?.length && activityData.map((item) => item.name)) || [];
this.start_date = projectData?.start_date || '';
this.end_date = projectData?.end_date || '';
this.comments = projectData?.comments || '';
this.completion_status =
(projectData &&
projectData.end_date &&
moment(projectData.end_date).endOf('day').isBefore(moment()) &&
COMPLETION_STATUS.COMPLETED) ||
COMPLETION_STATUS.ACTIVE;
this.publish_date = projectData?.publish_date || '';
}
}

/**
* Pre-processes GET /projects/{id} coordinator data for public (published) projects
*
Expand Down
2 changes: 1 addition & 1 deletion api/src/paths/public/project/{projectId}/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function getPublicProjectForView(): RequestHandler {
const projectService = new ProjectService(connection);

const result = await projectService.getPublicProjectById(Number(req.params.projectId));

console.log('result is: ', result);
await connection.commit();

return res.status(200).json(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,16 @@ import { describe } from 'mocha';
import {
countPendingAdministrativeActivitiesSQL,
getAdministrativeActivitiesSQL,
getAdministrativeActivityById,
postAdministrativeActivitySQL,
putAdministrativeActivitySQL
} from './administrative-activity-queries';

describe('getAdministrativeActivitiesSQL', () => {
it('returns non null response when no administrativeActivityTypeName or administrativeActivityStatusTypes provided', () => {
it('returns null response when no administrativeActivityTypeName or administrativeActivityStatusTypes provided', () => {
const response = getAdministrativeActivitiesSQL();

expect(response).to.not.be.null;
});

it('returns non null response when administrativeActivityStatusTypes is null and administrativeActivityStatusTypes is valid', () => {
const response = getAdministrativeActivitiesSQL((null as unknown) as string, ['status']);

expect(response).to.not.be.null;
});

it('returns non null response when administrativeActivityStatusTypes is empty string and administrativeActivityStatusTypes is valid', () => {
const response = getAdministrativeActivitiesSQL('', ['status']);

expect(response).to.not.be.null;
});

it('returns non null response when administrativeActivityStatusTypes is valid and administrativeActivityStatusTypes is null', () => {
const response = getAdministrativeActivitiesSQL('type', (null as unknown) as string[]);

expect(response).to.not.be.null;
expect(response).to.be.null;
});

it('returns non null response when administrativeActivityStatusTypes is valid and administrativeActivityStatusTypes is empty', () => {
Expand Down Expand Up @@ -62,6 +45,20 @@ describe('postAdministrativeActivitySQL', () => {
});
});

describe('getAdministrativeActivityById', () => {
it('returns null response when no getAdministrativeActivityById provided', () => {
const response = getAdministrativeActivityById((null as unknown) as number);

expect(response).to.be.null;
});

it('returns non null response when valid parameters provided', () => {
const response = getAdministrativeActivityById(1);

expect(response).to.not.be.null;
});
});

describe('countPendingAdministrativeActivitiesSQL', () => {
it('has a null userIdentifier', () => {
const response = countPendingAdministrativeActivitiesSQL((null as unknown) as string);
Expand All @@ -81,7 +78,7 @@ describe('putAdministrativeActivitySQL', () => {
});

it('has a null administrativeActivityStatusTypeId', () => {
const response = putAdministrativeActivitySQL((null as unknown) as number, 1);
const response = putAdministrativeActivitySQL(1, (null as unknown) as number);
expect(response).to.be.null;
});

Expand Down
Loading

0 comments on commit 2e17e22

Please sign in to comment.