Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BHBC-1922 #817

Merged
merged 18 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 232 additions & 5 deletions api/src/models/project-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { expect } from 'chai';
import { describe } from 'mocha';
import { COMPLETION_STATUS } from '../constants/status';
import {
GetAttachmentsData,
GetCoordinatorData,
GetFundingData,
GetIUCNClassificationData,
GetLocationData,
GetObjectivesData,
GetPartnershipsData,
GetPermitData,
GetProjectData
GetProjectData,
GetReportAttachmentsData
} from './project-view';

describe('GetProjectData', () => {
Expand Down Expand Up @@ -110,7 +112,8 @@ describe('GetObjectivesData', () => {

const obj = {
objectives: 'these are the project objectives',
caveats: 'these are some interesting caveats'
caveats: 'these are some interesting caveats',
revision_count: 'revision'
};

before(() => {
Expand All @@ -124,6 +127,10 @@ describe('GetObjectivesData', () => {
it('sets caveats', function () {
expect(projectObjectivesData.caveats).to.equal(obj.caveats);
});

it('sets revision_count', function () {
expect(projectObjectivesData.revision_count).to.equal(obj.revision_count);
});
});
});

Expand Down Expand Up @@ -164,7 +171,8 @@ describe('GetCoordinatorData', () => {
coordinator_last_name: 'last',
coordinator_email_address: '[email protected]',
coordinator_agency_name: 'agency',
coordinator_public: true
coordinator_public: true,
revision_count: 'count'
};

before(() => {
Expand All @@ -190,6 +198,10 @@ describe('GetCoordinatorData', () => {
it('sets share_contact_details', function () {
expect(projectCoordinatorData.share_contact_details).to.equal('true');
});

it('sets revision_count', function () {
expect(projectCoordinatorData.revision_count).to.equal('count');
});
});
});

Expand Down Expand Up @@ -284,11 +296,13 @@ describe('GetLocationData', () => {
const locationDataObj = [
{
location_description,
geometry
geometry,
revision_count: 'count'
},
{
location_description,
geometry
geometry,
revision_count: 'count'
}
];

Expand All @@ -303,6 +317,10 @@ describe('GetLocationData', () => {
it('sets the geometry', function () {
expect(locationData.geometry).to.eql(geometry);
});

it('sets revision_count', function () {
expect(locationData.revision_count).to.equal('count');
});
});
});

Expand Down Expand Up @@ -501,3 +519,212 @@ describe('GetPartnershipsData', () => {
});
});
});

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

before(() => {
data = new GetAttachmentsData((null as unknown) as any[]);
});

it('sets attachmentDetails', function () {
expect(data.attachmentDetails).to.eql([]);
});
});

describe('Empty arrays as values provided', () => {
let data: GetAttachmentsData;

before(() => {
data = new GetAttachmentsData([]);
});

it('sets attachmentDetails', function () {
expect(data.attachmentDetails).to.eql([]);
});
});

describe('some attachmentDetails values provided', () => {
let data: GetAttachmentsData;

const attachmentDetails = [{ file_name: 1 }, { file_name: 2 }];

before(() => {
data = new GetAttachmentsData(attachmentDetails);
});

it('sets file_name', function () {
expect(data.attachmentDetails).to.eql([
{
file_name: 1,
file_type: undefined,
title: undefined,
description: undefined,
key: undefined,
file_size: undefined,
is_secure: 'false'
},
{
file_name: 2,
file_type: undefined,
title: undefined,
description: undefined,
key: undefined,
file_size: undefined,
is_secure: 'false'
}
]);
});
});

describe('all attachmentDetails values provided', () => {
let data: GetAttachmentsData;

const attachmentDetails = [
{
file_name: 1,
file_type: 'type',
title: 'title',
description: 'descript',
security_token: 'key',
file_size: 'file_size',
key: 'key'
},
{
file_name: 2,
file_type: 'type',
title: 'title',
description: 'descript',
security_token: 'key',
file_size: 'file_size',
key: 'key'
}
];

before(() => {
data = new GetAttachmentsData(attachmentDetails);
});

it('sets all fields', function () {
expect(data.attachmentDetails).to.eql([
{
file_name: 1,
file_type: 'type',
title: 'title',
description: 'descript',
key: '',
file_size: 'file_size',
is_secure: 'true'
},
{
file_name: 2,
file_type: 'type',
title: 'title',
description: 'descript',
key: '',
file_size: 'file_size',
is_secure: 'true'
}
]);
});
});
});

describe('GetReportAttachmentsData', () => {
describe('No values provided', () => {
it('sets attachmentDetails', function () {
const data: GetReportAttachmentsData = new GetReportAttachmentsData((null as unknown) as any[]);

expect(data.attachmentDetails).to.eql([]);
});
});

describe('Empty arrays as values provided', () => {
it('sets attachmentDetails', function () {
const data: GetReportAttachmentsData = new GetReportAttachmentsData([]);

expect(data.attachmentDetails).to.eql([]);
});
});

describe('some attachmentDetails asdasdsadsasd values provided', () => {
it('sets file_name', function () {
const attachmentDetails = [{ file_name: 1 }, { file_name: 2 }];

const data: GetReportAttachmentsData = new GetReportAttachmentsData(attachmentDetails);
expect(data.attachmentDetails).to.eql([
{
file_name: 1,
title: undefined,
year: undefined,
description: undefined,
key: undefined,
file_size: undefined,
is_secure: 'false'
},
{
file_name: 2,
title: undefined,
year: undefined,
description: undefined,
key: undefined,
file_size: undefined,
is_secure: 'false'
}
]);
});
});

describe('all attachmentDetails values provided', () => {
it('sets all fields', function () {
const attachmentDetails = [
{
file_name: 1,
title: 'title',
year: '1',
description: 'descript',
security_token: 'key',
file_size: 'size',
key: 'key',
authors: [{ author: 'author' }]
},
{
file_name: 2,
file_type: 'type',
title: 'title',
year: '2',
description: 'descript',
security_token: 'key',
file_size: 'size',
key: 'key',
authors: [{ author: 'author' }]
}
];
const data: GetReportAttachmentsData = new GetReportAttachmentsData(attachmentDetails);

expect(data.attachmentDetails).to.eql([
{
file_name: 1,
title: 'title',
year: '1',
description: 'descript',
key: '',
file_size: 'size',
is_secure: 'true',
authors: [{ author: 'author' }]
},
{
file_name: 2,
title: 'title',
year: '2',
description: 'descript',
key: '',
file_size: 'size',
is_secure: 'true',
authors: [{ author: 'author' }]
}
]);
});
});
});
81 changes: 81 additions & 0 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,84 @@ export class GetPartnershipsData {
(stakeholder_partnerships?.length && stakeholder_partnerships.map((item: any) => item.partnership_name)) || [];
}
}

interface IGetAttachmentsSource {
file_name: string;
file_type: string;
title: string;
description: string;
key: string;
file_size: string;
is_secure: string;
}

/**
* Pre-processes GET /projects/{id} attachments data
*
* @export
* @class GetAttachmentsData
*/
export class GetAttachmentsData {
attachmentDetails: IGetAttachmentsSource[];

constructor(attachments?: any[]) {
this.attachmentDetails =
(attachments?.length &&
attachments.map((item: any) => {
return {
file_name: item.file_name,
file_type: item.file_type,
title: item.title,
description: item.description,
key: item.security_token ? '' : item.key,
file_size: item.file_size,
is_secure: item.security_token ? 'true' : 'false'
};
})) ||
[];
}
}

interface IGetReportAttachmentsSource {
file_name: string;
title: string;
year: string;
description: string;
key: string;
file_size: string;
is_secure: string;
authors?: { author: string }[];
}

/**
* Pre-processes GET /projects/{id} report attachments data
*
* @export
* @class GetReportAttachmentsData
*/
export class GetReportAttachmentsData {
attachmentDetails: IGetReportAttachmentsSource[];

constructor(attachments?: any[]) {
this.attachmentDetails =
(attachments?.length &&
attachments.map((item: any) => {
const attachmentItem = {
file_name: item.file_name,
title: item.title,
year: item.year,
description: item.description,
key: item.security_token ? '' : item.key,
file_size: item.file_size,
is_secure: item.security_token ? 'true' : 'false'
};

if (item.authors?.length) {
attachmentItem['authors'] = item.authors;
}

return attachmentItem;
})) ||
[];
}
}
Loading