Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d82d94e
refactoring page, pulling out components
al-rosenthal Mar 30, 2023
7d239af
fixed onclicks
al-rosenthal Mar 30, 2023
234a568
error component
al-rosenthal Mar 30, 2023
9b48896
stubbing out another component
al-rosenthal Mar 30, 2023
ccefdb9
Componentize more sections of publish button
KjartanE Mar 30, 2023
ee2012c
got errors displaying
al-rosenthal Mar 30, 2023
4ba014f
Update SurveyObservations.tsx and SubmissionAlertBar.tsx
NickPhura Mar 30, 2023
6518bee
renamed folder
al-rosenthal Mar 30, 2023
6fc7ea0
Fix lint issue
NickPhura Mar 30, 2023
4576180
Merge branch 'BHBC-2286' of https://github.com/bcgov/biohubbc into BH…
NickPhura Mar 30, 2023
127cd95
moved things into component folder
al-rosenthal Mar 30, 2023
eb697ed
Tweak Message HTML
NickPhura Mar 30, 2023
b1b10ae
Merge branch 'BHBC-2286' of https://github.com/bcgov/biohubbc into BH…
NickPhura Mar 30, 2023
069d241
fixing more state issues
al-rosenthal Mar 31, 2023
8992258
Merge branch 'BHBC-2286' of https://github.com/bcgov/biohubbc into BH…
KjartanE Mar 31, 2023
1deb1c6
message/ file display better
al-rosenthal Mar 31, 2023
49d537c
BHBC-2266: Add project supplementary data + fix tests
NickPhura Mar 31, 2023
ce7d37b
Fix merge issues
NickPhura Mar 31, 2023
17f4d54
small tweaks
al-rosenthal Mar 31, 2023
0a0d1eb
Merge branch 'BHBC-2286' of https://github.com/bcgov/biohubbc into BH…
al-rosenthal Mar 31, 2023
bdcc52f
Main ticket functioning, mvp
KjartanE Mar 31, 2023
1f1d964
Merge branch 'BHBC-2286' into feature_branch
al-rosenthal Mar 31, 2023
ef9c1fc
Merge remote-tracking branch 'origin/dev' into feature_branch
NickPhura Mar 31, 2023
4791a2e
Merge branch 'BHBC-2266' into feature_branch
NickPhura Mar 31, 2023
e463d4e
Pull observation id from observation dataloader
NickPhura Mar 31, 2023
b57c220
Remove unused variable
NickPhura Mar 31, 2023
fed1121
fixed loading states and definitions
al-rosenthal Mar 31, 2023
6b074c1
clean up
al-rosenthal Apr 1, 2023
a5621cc
Observation Validation fix
KjartanE Apr 3, 2023
fbd361d
Update project components to use context.
NickPhura Apr 4, 2023
182d567
Merge branch 'feature_branch' of https://github.com/bcgov/biohubbc in…
NickPhura Apr 4, 2023
99aa35d
Update project participants components
NickPhura Apr 4, 2023
fde1757
update observation upload icon
KjartanE Apr 4, 2023
8979ec2
Merge branch 'dev' of https://github.com/bcgov/biohubbc into feature_…
KjartanE Apr 4, 2023
6881b12
code smells
KjartanE Apr 4, 2023
9269719
added logic to context refresh
al-rosenthal Apr 4, 2023
4ec8f07
Merge branch 'feature_branch' of https://github.com/bcgov/biohubbc in…
al-rosenthal Apr 4, 2023
9380581
code smells, api test fix
KjartanE Apr 4, 2023
fc8e24a
Merge branch 'feature_branch' of https://github.com/bcgov/biohubbc in…
KjartanE Apr 4, 2023
ba27994
Move project participation repo functions to own repo file
NickPhura Apr 4, 2023
d027354
Merge branch 'feature_branch' of https://github.com/bcgov/biohubbc in…
NickPhura Apr 4, 2023
34d7941
Updates
NickPhura Apr 5, 2023
3481490
fix frontend tests
KjartanE Apr 5, 2023
163e26c
Fix api test
NickPhura Apr 5, 2023
2ce43a9
Update app tests
NickPhura Apr 6, 2023
b8ee72f
ignore-skip
NickPhura Apr 6, 2023
2e50c70
Update create/edit survey to use contexts, fix bug with taxon multise…
NickPhura Apr 6, 2023
2ce9bd6
Fix test to avoid warning
NickPhura Apr 6, 2023
66c699d
stubbing out testing
al-rosenthal Apr 6, 2023
9434e8d
Merge branch 'feature_branch' of https://github.com/bcgov/biohubbc in…
al-rosenthal Apr 6, 2023
54abd28
removed half test
al-rosenthal Apr 6, 2023
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
Prev Previous commit
Next Next commit
Updates
  • Loading branch information
NickPhura committed Apr 5, 2023
commit 34d7941469b63e258b64fbe2a1ca282bedce1bc2
86 changes: 28 additions & 58 deletions api/src/paths/user/{userId}/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import SQL from 'sql-template-strings';
import * as db from '../../../database/db';
import { HTTPError } from '../../../errors/http-error';
import project_participation_queries from '../../../queries/project-participation';
import user_queries from '../../../queries/users';
import { ProjectParticipationService } from '../../../services/project-participation-service';
import { UserService } from '../../../services/user-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../__mocks__/db';
import * as delete_endpoint from './delete';
Expand Down Expand Up @@ -35,72 +34,43 @@ describe('removeSystemUser', () => {
}
});

it('should throw a 400 error when no sql statement returned from `getParticipantsFromAllSystemUsersProjectsSQL`', async () => {
it('should throw a 400 error if the user is the only Project Lead role on one or more projects', async () => {
const dbConnectionObj = getMockDBConnection();

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.params = { userId: '1' };
mockReq.body = { roles: [1, 2] };

sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);

sinon.stub(project_participation_queries, 'getParticipantsFromAllSystemUsersProjectsSQL').returns(null);

try {
const requestHandler = delete_endpoint.removeSystemUser();

await requestHandler(mockReq, mockRes, mockNext);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).status).to.equal(400);
expect((actualError as HTTPError).message).to.equal('Failed to build SQL get statement');
}
});

it('should throw a 400 error if the user is the only Project Lead role on one or more projects', async () => {
const dbConnectionObj = getMockDBConnection();

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.params = { userId: '33' };
mockReq.body = { roles: [1, 2] };

const mockQuery = sinon.stub();

mockQuery.resolves({
rowCount: 2,
rows: [
{
project_participation_id: 47,
project_id: 3,
system_user_id: 33,
project_role_id: 1,
project_role_name: 'Project Lead'
},
{
project_participation_id: 57,
project_id: 1,
system_user_id: 33,
project_role_id: 3,
project_role_name: 'Viewer'
},
{
project_participation_id: 40,
project_id: 1,
system_user_id: 27,
project_role_id: 1,
project_role_name: 'Project Lead'
}
]
});

sinon.stub(db, 'getDBConnection').returns({
...dbConnectionObj,
query: mockQuery
});
const mockResponse = [
{
project_participation_id: 47,
project_id: 3,
system_user_id: 33,
project_role_id: 1,
project_role_name: 'Project Lead'
},
{
project_participation_id: 57,
project_id: 1,
system_user_id: 33,
project_role_id: 3,
project_role_name: 'Viewer'
},
{
project_participation_id: 40,
project_id: 1,
system_user_id: 27,
project_role_id: 1,
project_role_name: 'Project Lead'
}
];

sinon.stub(project_participation_queries, 'getParticipantsFromAllSystemUsersProjectsSQL').returns(SQL`some query`);
sinon
.stub(ProjectParticipationService.prototype, 'getParticipantsFromAllProjectsBySystemUserId')
.resolves(mockResponse);

try {
const requestHandler = delete_endpoint.removeSystemUser();
Expand Down
34 changes: 6 additions & 28 deletions api/src/paths/user/{userId}/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDBConnection, IDBConnection } from '../../../database/db';
import { HTTP400 } from '../../../errors/http-error';
import { queries } from '../../../queries/queries';
import { authorizeRequestHandler } from '../../../request-handlers/security/authorization';
import { ProjectParticipationService } from '../../../services/project-participation-service';
import { UserService } from '../../../services/user-service';
import { getLogger } from '../../../utils/logger';

Expand Down Expand Up @@ -113,7 +114,11 @@ export function removeSystemUser(): RequestHandler {
}

export const checkIfUserIsOnlyProjectLeadOnAnyProject = async (userId: number, connection: IDBConnection) => {
const getAllParticipantsResponse = await getAllParticipantsFromSystemUsersProjects(userId, connection);
const projectParticipationService = new ProjectParticipationService(connection);

const getAllParticipantsResponse = await projectParticipationService.getParticipantsFromAllProjectsBySystemUserId(
userId
);

// No projects associated to user, skip Project Lead role check
if (!getAllParticipantsResponse.length) {
Expand All @@ -137,33 +142,6 @@ export const deleteAllProjectRoles = async (userId: number, connection: IDBConne
connection.query(sqlStatement.text, sqlStatement.values);
};

/**
* collect all participants associated with user across all projects.
*
* @param {number} userId
* @param {IDBConnection} connection
* @return {*} {Promise<any[]>}
*/
export const getAllParticipantsFromSystemUsersProjects = async (
userId: number,
connection: IDBConnection
): Promise<any[]> => {
const getParticipantsFromAllSystemUsersProjectsSQLStatment = queries.projectParticipation.getParticipantsFromAllSystemUsersProjectsSQL(
userId
);

if (!getParticipantsFromAllSystemUsersProjectsSQLStatment) {
throw new HTTP400('Failed to build SQL get statement');
}

const response = await connection.query(
getParticipantsFromAllSystemUsersProjectsSQLStatment.text,
getParticipantsFromAllSystemUsersProjectsSQLStatment.values
);

return response.rows || [];
};

/**
* Given an array of project participation role objects, return false if any project has no Project Lead role. Return
* true otherwise.
Expand Down
123 changes: 39 additions & 84 deletions api/src/paths/user/{userId}/projects/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,74 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import SQL from 'sql-template-strings';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import project_participation_queries from '../../../../queries/project-participation';
import { getMockDBConnection } from '../../../../__mocks__/db';
import { ProjectParticipationService } from '../../../../services/project-participation-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../__mocks__/db';
import * as projects from './get';

chai.use(sinonChai);

describe('projects', () => {
const dbConnectionObj = getMockDBConnection();

describe('getAllUserProjects', () => {
afterEach(() => {
sinon.restore();
});

const sampleReq = {
keycloak_token: {},
params: {
userId: 1
}
} as any;
it('finds user by Id and returns 200 and result on success', async () => {
const dbConnectionObj = getMockDBConnection();
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);

let actualResult: any = null;
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

const sampleRes = {
status: () => {
return {
json: (result: any) => {
actualResult = result;
}
};
}
};
mockReq.params = {
userId: '1'
};

it('should throw a 400 error when no params are sent', async () => {
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);
const getProjectsBySystemUserIdStub = sinon
.stub(ProjectParticipationService.prototype, 'getProjectsBySystemUserId')
.resolves([
{ project_id: 123, name: 'test', system_user_id: 12, project_role_id: 42, project_participation_id: 88 }
]);

try {
const result = projects.getAllUserProjects();
const requestHandler = projects.getAllUserProjects();

await result({ ...(sampleReq as any), params: null }, (null as unknown) as any, (null as unknown) as any);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).status).to.equal(400);
expect((actualError as HTTPError).message).to.equal('Missing required params');
}
await requestHandler(mockReq, mockRes, mockNext);

expect(getProjectsBySystemUserIdStub).to.have.been.calledOnceWith(1);

expect(mockRes.jsonValue).to.eql([
{ project_id: 123, name: 'test', system_user_id: 12, project_role_id: 42, project_participation_id: 88 }
]);
});

it('should throw a 400 error when no user Id is sent', async () => {
it('catches error, calls rollback, and re-throws error', async () => {
const dbConnectionObj = getMockDBConnection();
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);

try {
const result = projects.getAllUserProjects();
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

await result(
{ ...(sampleReq as any), params: { ...sampleReq.params, userId: null } },
(null as unknown) as any,
(null as unknown) as any
);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).status).to.equal(400);
expect((actualError as HTTPError).message).to.equal('Missing required param: userId');
}
});
mockReq.params = {
userId: '1'
};

it('should throw a 400 error when no sql statement returned for getProjectSQL', async () => {
sinon.stub(db, 'getDBConnection').returns({
...dbConnectionObj,
systemUserId: () => {
return 20;
}
});
const getProjectsBySystemUserIdStub = sinon
.stub(ProjectParticipationService.prototype, 'getProjectsBySystemUserId')
.resolves([
{ project_id: 123, name: 'test', system_user_id: 12, project_role_id: 42, project_participation_id: 88 }
]);

sinon.stub(project_participation_queries, 'getAllUserProjectsSQL').returns(null);
const requestHandler = projects.getAllUserProjects();

try {
const result = projects.getAllUserProjects();

await result(sampleReq, (null as unknown) as any, (null as unknown) as any);
await requestHandler(mockReq, mockRes, mockNext);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).status).to.equal(400);
expect((actualError as HTTPError).message).to.equal('Failed to build SQL get statement');
}
});

it('finds user by Id and returns 200 and result on success', async () => {
const mockQuery = sinon.stub();
expect(dbConnectionObj.release).to.have.been.called;
expect(getProjectsBySystemUserIdStub).not.to.have.been.called;

mockQuery.resolves({
rows: [{ project_id: 123, name: 'test', system_user_id: 12, project_role_id: 42, project_participation_id: 88 }]
});

sinon.stub(db, 'getDBConnection').returns({
...dbConnectionObj,
systemUserId: () => {
return 20;
},
query: mockQuery
});

sinon.stub(project_participation_queries, 'getAllUserProjectsSQL').returns(SQL`something`);

const result = projects.getAllUserProjects();

await result(sampleReq, sampleRes as any, (null as unknown) as any);

expect(actualResult).to.eql([
{ project_id: 123, name: 'test', system_user_id: 12, project_role_id: 42, project_participation_id: 88 }
]);
expect((actualError as HTTPError).message).to.equal('a test error');
}
});
});
});
Loading