Skip to content

Commit

Permalink
Merge pull request #44 from dadiorchen/seec-cli
Browse files Browse the repository at this point in the history
feat: add capture_count
  • Loading branch information
dadiorchen authored Mar 15, 2022
2 parents d326b27 + 48e7e17 commit 3caea8c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion __tests__/api-tests/earnings-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ describe('Earnings API tests.', () => {
expect(earning).to.have.keys([
'id',
'grower',
'funder',
'captures_count',
'phone',
'worker_id',
Expand Down Expand Up @@ -653,6 +652,7 @@ describe('Earnings API tests.', () => {
});

it(`Successful batch request`, function (done) {

request(server)
.patch(`/earnings/batch`)
.set('Accept', 'multipart/form-data')
Expand Down
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidHeader.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_id
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_id
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidHeader2.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,worker_id,phone,currency,amount,payment_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,currency,amount,captures_count,payment_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidHeader3.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,phone,currency,amount,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidHeader5.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,worker_id,phone,amount,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,amount,captures_count,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidHeader6.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_id,phone,currency,amount,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
worker_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_method
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsFailedTestInvalidRow.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed6,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed6,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
9c10e443-4e08-40d4-9b73-5a931886f896,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
3ab96dfd-274a-4097-8e7d-942e58203784,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
9c10e443-4e08-40d4-9b73-5a931886f896,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
3ab96dfd-274a-4097-8e7d-942e58203784,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
8 changes: 4 additions & 4 deletions __tests__/api-tests/earningsSuccessfulTest.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
earnings_id,worker_id,phone,currency,amount,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,4,jomzy jor jor,2021-10-10T00:00:00.000Z
earnings_id,worker_id,phone,currency,amount,captures_count,payment_confirmation_id,payment_method,paid_at
f3056760-4c36-4cf7-b625-ed656d314794,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,2,jomzy jor jor,2021-10-10T00:00:00.000Z
a69e5cec-945f-4693-8a94-01623ee44187,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,3,jomzy jor jor,2021-10-10T00:00:00.000Z
61714d24-6131-4296-ae36-30a7199cc645,71be6266-81fe-476f-a563-9bc1c61fc037,Not sure for now,USD,700,22,4,jomzy jor jor,2021-10-10T00:00:00.000Z
15 changes: 8 additions & 7 deletions __tests__/api-tests/seed-data-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const workerId = '71be6266-81fe-476f-a563-9bc1c61fc037';
const earningsPaymentObject = {
worker_id: workerId,
amount: 700,
captures_count: 22,
payment_confirmation_id: uuid(),
payment_method: 'cash',
currency: 'USD',
Expand Down Expand Up @@ -59,14 +60,14 @@ before(async () => {
await knex.raw(`
INSERT INTO earnings(
id, worker_id, funder_id, amount, currency, calculated_at, consolidation_rule_id, consolidation_period_start, consolidation_period_end, payment_confirmed_by, payment_confirmation_method, status, active, contract_id)
id, worker_id, funder_id, amount, captures_count, currency, calculated_at, consolidation_rule_id, consolidation_period_start, consolidation_period_end, payment_confirmed_by, payment_confirmation_method, status, active, contract_id)
VALUES
('${earningsOne.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsOne.status}', true, '${uuid()}'),
('${earningsTwo.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsTwo.status}', true, '${uuid()}'),
('${earningsThree.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsThree.status}', true, '${uuid()}'),
('${earningsFour.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'batch', '${earningsFour.status}', true, '${uuid()}'),
('${earningsWithCancelledStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsWithCancelledStatus.status}', true, '${uuid()}'),
('${earningsWithPaidStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsWithPaidStatus.status}', true, '${uuid()}');
('${earningsOne.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}', '${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsOne.status}', true, '${uuid()}'),
('${earningsTwo.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}','${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsTwo.status}', true, '${uuid()}'),
('${earningsThree.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}','${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsThree.status}', true, '${uuid()}'),
('${earningsFour.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}','${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'batch', '${earningsFour.status}', true, '${uuid()}'),
('${earningsWithCancelledStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}','${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsWithCancelledStatus.status}', true, '${uuid()}'),
('${earningsWithPaidStatus.id}','${workerId}', '${uuid()}', '${earningsPaymentObject.amount}','${earningsPaymentObject.captures_count}', '${earningsPaymentObject.currency}', now(), '${uuid()}', now(), now(), 1,'single', '${earningsWithPaidStatus.status}', true, '${uuid()}');
`);
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/api-tests/seed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("seed", () => {
await knex("earnings").truncate();
})

it.only("seed", async () => {
it.skip("seed", async () => {
await seed.seed(
'4c46cdae-d15b-454e-a7e4-570c4895b3f8',
'ae7faf5d-46e2-4944-a6f9-5e65986b2e03',
Expand Down
1 change: 1 addition & 0 deletions server/handlers/earningsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const earningsPatchSchema = Joi.object({
earnings_id: Joi.string().uuid(),
worker_id: Joi.string().uuid().required(),
amount: Joi.number().required(),
captures_count: Joi.number().required(),
currency: Joi.string().required(),
payment_confirmation_id: Joi.string().required(),
payment_method: Joi.string().required(),
Expand Down
11 changes: 10 additions & 1 deletion server/models/Earnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const getEarnings =

const updateEarnings = async (earningsRepo, requestBody) => {
const body = { ...requestBody };
const { worker_id, currency, amount } = body;
const { worker_id, currency, amount, captures_count } = body;

// If data is coming from csv file
if (body.earnings_id) {
Expand Down Expand Up @@ -261,6 +261,15 @@ const updateEarnings = async (earningsRepo, requestBody) => {
'The amount specified does not match that of the earning',
);

if (+earnings.captures_count !== +captures_count) {
console.error("earnings", earnings);
console.error("captures_count", captures_count);
throw new HttpError(
409,
'The captures_count specified does not match that of the earning',
);
}

await earningsRepo.update({
...body,
status: 'paid',
Expand Down

0 comments on commit 3caea8c

Please sign in to comment.