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

feat(mojaloop/#3564): multi insert quote party extensions #319

Merged
merged 3 commits into from
Oct 17, 2023
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 11 additions & 16 deletions src/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,7 @@ class Database {
const extensions = party.partyIdInfo.extensionList.extension
// we need to store personal info also
const quoteParty = await this.getTxnQuoteParty(txn, quoteId, partyType)
for (const extension of extensions) {
const newExtensions = {
key: extension.key,
value: extension.value
}
const createQuotePartyIdInfoExtension = await this.createQuotePartyIdInfoExtension(txn, newExtensions, quoteParty)
this.writeLog(`inserted new QuotePartyIdInfoExtension in db: ${util.inspect(createQuotePartyIdInfoExtension)}`)
}
await this.createQuotePartyIdInfoExtensions(txn, extensions, quoteParty)
}

return quotePartyId
Expand All @@ -541,7 +534,7 @@ class Database {
}

/**
* Creates the specifid party and returns its id
* Creates the specific party and returns its id
*
* @returns {promise} - id of party
*/
Expand Down Expand Up @@ -597,18 +590,20 @@ class Database {
}
}

async createQuotePartyIdInfoExtension (txn, extensionList, quoteParty) {
async createQuotePartyIdInfoExtensions (txn, extensions, quoteParty) {
try {
const newExtensions = extensions.map(({ key, value }) => ({
quotePartyId: quoteParty.quotePartyId,
key,
value
}))

await this.queryBuilder('quotePartyIdInfoExtension')
.transacting(txn)
.insert({
quotePartyId: quoteParty.quotePartyId,
key: extensionList.key,
value: extensionList.value
})
.insert(newExtensions)
return true
} catch (err) {
this.writeLog(`Error in createQuotePartyIdInfoExtension: ${getStackOrInspect(err)}`)
this.writeLog(`Error in createQuotePartyIdInfoExtensions: ${getStackOrInspect(err)}`)
throw ErrorHandler.Factory.reformatFSPIOPError(err)
}
}
Expand Down
42 changes: 26 additions & 16 deletions test/unit/data/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ describe('/database', () => {
database.getTransferParticipantRoleType = jest.fn().mockResolvedValueOnce('testTransferParticipantRoleTypeId')
database.getLedgerEntryType = jest.fn().mockResolvedValueOnce('testLedgerEntryTypeId')
database.getTxnQuoteParty = jest.fn().mockResolvedValueOnce(quoteParty)
database.createQuotePartyIdInfoExtension = jest.fn().mockResolvedValueOnce(true)
database.createQuotePartyIdInfoExtensions = jest.fn().mockResolvedValueOnce(true)
})

it('Creates a quote party', async () => {
Expand Down Expand Up @@ -1396,16 +1396,17 @@ describe('/database', () => {
})
})

describe('createQuotePartyIdInfoExtension', () => {
const mockQuotePartyIdInfoExtension = {
quotePartyId: 'ddaa67b3-5bf8-45c1-bfcf-1e8781177c37',
key: 'Test',
value: 'data'
}
const extensionList = {
key: 'Test',
value: 'data'
}
describe('createQuotePartyIdInfoExtensions', () => {
const extensions = [
{
key: 'Test',
value: 'data'
},
{
key: 'Test1',
value: 'data1'
}
]
const quoteParty = {
quotePartyId: 'ddaa67b3-5bf8-45c1-bfcf-1e8781177c37'
}
Expand All @@ -1418,12 +1419,21 @@ describe('/database', () => {
null,
['transacting', 'insert']
)
const expectedInsert = {
...mockQuotePartyIdInfoExtension
}
const expectedInsert = [
{
quotePartyId: quoteParty.quotePartyId,
key: 'Test',
value: 'data'
},
{
quotePartyId: quoteParty.quotePartyId,
key: 'Test1',
value: 'data1'
}
]

// Act
const result = await database.createQuotePartyIdInfoExtension(txn, extensionList, quoteParty)
const result = await database.createQuotePartyIdInfoExtensions(txn, extensions, quoteParty)

// Assert
expect(result).toEqual(true)
Expand All @@ -1438,7 +1448,7 @@ describe('/database', () => {
mockKnex.mockImplementationOnce(() => { throw new Error('Test Error') })

// Act
const action = async () => database.createQuotePartyIdInfoExtension(txn, extensionList, quoteParty)
const action = async () => database.createQuotePartyIdInfoExtensions(txn, extensions, quoteParty)

// Assert
await expect(action()).rejects.toThrowError('Test Error')
Expand Down
Loading