Skip to content

Commit

Permalink
accidentally messed with wrong file
Browse files Browse the repository at this point in the history
  • Loading branch information
lailien3 committed Dec 2, 2024
1 parent 2b191ea commit ff3e0ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('create-transactions', () => {
await createTransactions(`${Project.root}/src/__mocks__/test-2-records.xml`)
expectCreateTransactionCalls(2)
expect(db.updateRecordStagingTable.mock.calls).toHaveLength(2)
// First call to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls[0][1]).toHaveLength(2)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toEqual(
expect.arrayContaining([
Expand All @@ -38,13 +39,15 @@ describe('create-transactions', () => {
})
])
)
// Second call to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[1][1]).toHaveLength(0)
})

it('stages the 25 record test file (on batch-size boundary)', async () => {
salesApi.createTransactions.mockReturnValue(generateApiSuccessResponse(MAX_CREATE_TRANSACTION_BATCH_SIZE))
await createTransactions(`${Project.root}/src/__mocks__/test-25-records.xml`)
expectCreateTransactionCalls(MAX_CREATE_TRANSACTION_BATCH_SIZE)
// First call to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls).toHaveLength(2)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toHaveLength(MAX_CREATE_TRANSACTION_BATCH_SIZE)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toEqual(
Expand All @@ -55,6 +58,7 @@ describe('create-transactions', () => {
})
])
)
// Second call to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[1][1]).toHaveLength(0)
})

Expand All @@ -63,6 +67,7 @@ describe('create-transactions', () => {
await createTransactions(`${Project.root}/src/__mocks__/test-30-records.xml`)
expectCreateTransactionCalls(MAX_CREATE_TRANSACTION_BATCH_SIZE, 5)
expect(db.updateRecordStagingTable.mock.calls).toHaveLength(4)
// First call of first batch to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls[0][1]).toHaveLength(MAX_CREATE_TRANSACTION_BATCH_SIZE)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toEqual(
expect.arrayContaining([
Expand All @@ -72,7 +77,10 @@ describe('create-transactions', () => {
})
])
)
// Second call of first batch to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[1][1]).toHaveLength(0)

// First call of second batch to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls[2][1]).toHaveLength(5)
expect(db.updateRecordStagingTable.mock.calls[2][1]).toEqual(
expect.arrayContaining([
Expand All @@ -82,6 +90,7 @@ describe('create-transactions', () => {
})
])
)
// Second call of second batch to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[3][1]).toHaveLength(0)
})

Expand All @@ -91,6 +100,7 @@ describe('create-transactions', () => {
await createTransactions(`${Project.root}/src/__mocks__/test-2-records.xml`)
expectCreateTransactionCalls(1)
expect(db.updateRecordStagingTable.mock.calls).toHaveLength(2)
// First call to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls[0][1]).toHaveLength(1)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toEqual(
expect.arrayContaining([
Expand All @@ -100,6 +110,7 @@ describe('create-transactions', () => {
})
])
)
// Second call to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[1][1]).toHaveLength(0)
})

Expand All @@ -109,6 +120,7 @@ describe('create-transactions', () => {
await createTransactions(`${Project.root}/src/__mocks__/test-2-records.xml`)
expectCreateTransactionCalls(1)
expect(db.updateRecordStagingTable.mock.calls).toHaveLength(2)
// First call to update records which were successfully created
expect(db.updateRecordStagingTable.mock.calls[0][1]).toHaveLength(1)
expect(db.updateRecordStagingTable.mock.calls[0][1]).toEqual(
expect.arrayContaining([
Expand All @@ -118,6 +130,7 @@ describe('create-transactions', () => {
})
])
)
// Second call to update records which failed (there shouldn't be any for this test)
expect(db.updateRecordStagingTable.mock.calls[1][1]).toHaveLength(0)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const debug = db('sales:paymentjournals')
* @param {*} payload
* @returns {Promise<*>}
*/
export async function createPaymentJournal (id, payload, expires = Math.floor(Date.now() / 1000) + PAYMENTS_TABLE.Ttl) {
const record = { id, expires, ...payload }
export async function createPaymentJournal (id, payload) {
const record = { id, expires: Math.floor(Date.now() / 1000) + PAYMENTS_TABLE.Ttl, ...payload }
await docClient.send(
new PutCommand({
TableName: PAYMENTS_TABLE.TableName,
Expand All @@ -28,8 +28,8 @@ export async function createPaymentJournal (id, payload, expires = Math.floor(Da
* @param {*} payload
* @returns {Promise<*>}
*/
export async function updatePaymentJournal (id, payload, expires = Math.floor(Date.now() / 1000) + PAYMENTS_TABLE.Ttl) {
const updates = { expires, ...payload }
export async function updatePaymentJournal (id, payload) {
const updates = { expires: Math.floor(Date.now() / 1000) + PAYMENTS_TABLE.Ttl, ...payload }
const updateExpression =
'SET ' +
Object.keys(updates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ export async function processQueue ({ id }) {
await docClient.send(
new PutCommand({
TableName: TRANSACTION_STAGING_HISTORY_TABLE.TableName,
Item: {
...transactionRecord,
expires: Math.floor(Date.now() / 1000) + TRANSACTION_STAGING_HISTORY_TABLE.Ttl
},
Item: Object.assign(transactionRecord, { expires: Math.floor(Date.now() / 1000) + TRANSACTION_STAGING_HISTORY_TABLE.Ttl }),
ConditionExpression: 'attribute_not_exists(id)'
})
)
Expand Down Expand Up @@ -167,9 +164,8 @@ const createTransactionEntities = async transactionRecord => {
transaction.channelId = transactionRecord.channelId

transaction.bindToEntity(Transaction.definition.relationships.transactionCurrency, currency)
if (transactionRecord.transactionFile) {
transactionRecord.transactionFile &&
transaction.bindToAlternateKey(Transaction.definition.relationships.poclFile, transactionRecord.transactionFile)
}

const chargeJournal = await createTransactionJournal(transactionRecord, transaction, 'Charge', currency)
const paymentJournal = await createTransactionJournal(transactionRecord, transaction, 'Payment', currency)
Expand Down

0 comments on commit ff3e0ba

Please sign in to comment.