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

attach respondent info to case #287

Merged
merged 3 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion shared/src/business/entities/Case.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const uuidVersions = {

const Document = require('./Document');

const docketNumberMatcher = /^\d{3,5}-\d{2}$/;
const docketNumberMatcher = /^(\d{3,5}-\d{2})$/;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding this

/**
* Case
* @param rawCase
Expand Down Expand Up @@ -57,6 +57,9 @@ joiValidationDecorator(
.regex(docketNumberMatcher)
.required(),
respondentId: joi.string().optional(),
respondentFirstName: joi.string().optional(),
respondentLastName: joi.string().optional(),
respondentBarNumber: joi.string().optional(),
irsSendDate: joi
.date()
.iso()
Expand Down Expand Up @@ -130,6 +133,11 @@ Case.isValidDocketNumber = docketNumber => {
);
};

Case.stripLeadingZeros = docketNumber => {
const [number, year] = docketNumber.split('-');
return `${parseInt(number)}-${year}`;
};

/**
* documentTypes
* @type {{petitionFile: string, requestForPlaceOfTrial: string, statementOfTaxpayerIdentificationNumber: string}}
Expand Down
2 changes: 1 addition & 1 deletion shared/src/business/useCases/getCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.getCase = async ({ userId, caseId, applicationContext }) => {
caseRecord = await applicationContext
.getPersistenceGateway()
.getCaseByDocketNumber({
docketNumber: caseId,
docketNumber: Case.stripLeadingZeros(caseId),
applicationContext,
});
}
Expand Down
18 changes: 11 additions & 7 deletions shared/src/business/useCases/getCase.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert');
const { getCase } = require('./getCase');
const sinon = require('sinon');
const { MOCK_DOCUMENTS } = require('../../test/mockDocuments');

const documents = MOCK_DOCUMENTS;
Expand Down Expand Up @@ -55,15 +56,14 @@ describe('Get case', () => {
});

it('success case by docket number', async () => {
const getCaseByDocketNumberStub = sinon.stub().resolves({
docketNumber: '00101-00',
caseId: 'c54ba5a9-b37b-479d-9201-067ec6e335bb',
documents,
});
applicationContext = {
getPersistenceGateway: () => ({
getCaseByDocketNumber: () => {
return Promise.resolve({
docketNumber: '00101-00',
caseId: 'c54ba5a9-b37b-479d-9201-067ec6e335bb',
documents,
});
},
getCaseByDocketNumber: getCaseByDocketNumberStub,
}),
environment: { stage: 'local' },
};
Expand All @@ -73,6 +73,10 @@ describe('Get case', () => {
applicationContext,
});
assert.equal(caseRecord.caseId, 'c54ba5a9-b37b-479d-9201-067ec6e335bb');
assert.equal(
getCaseByDocketNumberStub.getCall(0).args[0].docketNumber,
'101-00',
);
});

it('failure case by docket number', async () => {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/business/useCases/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const User = require('../entities/User');
* @param userId
* @returns {User}
*/
exports.getUser = userId => {
exports.getUser = async userId => {
try {
return new User({ userId });
} catch (err) {
Expand Down
8 changes: 4 additions & 4 deletions shared/src/business/useCases/getUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ const { getUser } = require('./getUser');

describe('Get user', () => {
it('Success taxpayer', async () => {
const user = getUser('taxpayer');
const user = await getUser('taxpayer');
assert.equal(user.userId, 'taxpayer');
assert.equal(user.role, 'taxpayer');
});
it('Success petitionsclerk', async () => {
const user = getUser('petitionsclerk');
const user = await getUser('petitionsclerk');
assert.equal(user.userId, 'petitionsclerk');
assert.equal(user.role, 'petitionsclerk');
});
it('Success intakeclerk', async () => {
const user = getUser('intakeclerk');
const user = await getUser('intakeclerk');
assert.equal(user.userId, 'intakeclerk');
assert.equal(user.role, 'intakeclerk');
});
it('Failure', async () => {
try {
getUser('Bad actor');
await getUser('Bad actor');
} catch (e) {
assert.equal(e.message, 'Username is incorrect');
}
Expand Down
6 changes: 6 additions & 0 deletions shared/src/business/useCases/respondent/fileAnswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ exports.fileAnswer = async ({
);
}

const user = await applicationContext.getUseCases().getUser(userId);

//upload to S3 return uuid
const answerDocumentId = await applicationContext
.getPersistenceGateway()
Expand All @@ -32,6 +34,10 @@ exports.fileAnswer = async ({

const caseWithAnswer = new Case({
...caseToUpdate,
respondentId: userId,
respondentBarNumber: user.barNumber,
respondentFirstName: user.firstName,
respondentLastName: user.lastName,
documents: [...caseToUpdate.documents, answerDocumentMetadata],
});

Expand Down
69 changes: 66 additions & 3 deletions shared/src/business/useCases/respondent/fileAnswer.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
const { fileAnswer } = require('./fileAnswer');
const sinon = require('sinon');
const expect = require('chai').expect;
const chai = require('chai');
chai.use(require('chai-string'));
const { MOCK_DOCUMENTS } = require('../../../test/mockDocuments');

describe('fileAnswer', () => {
let applicationContext;
let documents = MOCK_DOCUMENTS;

it('throws an error if the entity returned from persistence is invalid', async () => {
it('should attach the respondent information to the case when calling updateCase', async () => {
const updateCaseStub = sinon.stub().resolves({
docketNumber: '00101-18',
caseId: 'a6b81f4d-1e47-423a-8caf-6d2fdc3d3859',
documents,
});
applicationContext = {
getPersistenceGateway: () => {
return {
uploadDocument: () =>
Promise.resolve('a6b81f4d-1e47-423a-8caf-6d2fdc3d3859'),
};
},
getUseCases: () => {
return {
updateCase: updateCaseStub,
getUser: () =>
Promise.resolve({
firstName: 'bob',
lastName: 'marley',
barNumber: '12345',
}),
};
},
environment: { stage: 'local' },
};
await fileAnswer({
answerDocument: 'abc',
userId: 'respondent',
caseToUpdate: {
documents,
docketNumber: '00101-18',
caseId: 'a6b81f4d-1e47-423a-8caf-6d2fdc3d3859',
},
applicationContext,
});
expect(updateCaseStub.getCall(0).args[0].caseDetails).to.contain({
respondentId: 'respondent',
respondentFirstName: 'bob',
respondentLastName: 'marley',
respondentBarNumber: '12345',
});
});

it('throws an error is the entity returned from persistence is invalid', async () => {
applicationContext = {
getUseCases: () => ({
getUser: () =>
Promise.resolve({
firstName: 'bob',
lastName: 'marley',
barNumber: '12345',
}),
}),
getPersistenceGateway: () => {
return {
uploadDocument: () => Promise.resolve('abc'),
Expand All @@ -28,7 +85,7 @@ describe('fileAnswer', () => {
} catch (err) {
error = err;
}
expect(error.message).toContain(
expect(error.message).to.contain(
'The entity was invalid ValidationError: child',
);
});
Expand All @@ -48,6 +105,12 @@ describe('fileAnswer', () => {
docketNumber: '00101-18',
caseId: 'a6b81f4d-1e47-423a-8caf-6d2fdc3d3859',
}),
getUser: () =>
Promise.resolve({
firstName: 'bob',
lastName: 'marley',
barNumber: '12345',
}),
};
},
environment: { stage: 'local' },
Expand All @@ -67,6 +130,6 @@ describe('fileAnswer', () => {
} catch (err) {
error = err;
}
expect(error.message).toContain('The entity was invalid');
expect(error.message).to.contain('The entity was invalid');
});
});