@defra-fish/sales-api-service 1.50.0 → 1.51.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra-fish/sales-api-service",
3
- "version": "1.50.0",
3
+ "version": "1.51.0-rc.1",
4
4
  "description": "Rod Licensing Sales API",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,9 +35,9 @@
35
35
  "test": "echo \"Error: run tests from root\" && exit 1"
36
36
  },
37
37
  "dependencies": {
38
- "@defra-fish/business-rules-lib": "1.50.0",
39
- "@defra-fish/connectors-lib": "1.50.0",
40
- "@defra-fish/dynamics-lib": "1.50.0",
38
+ "@defra-fish/business-rules-lib": "1.51.0-rc.1",
39
+ "@defra-fish/connectors-lib": "1.51.0-rc.1",
40
+ "@defra-fish/dynamics-lib": "1.51.0-rc.1",
41
41
  "@hapi/boom": "^9.1.2",
42
42
  "@hapi/hapi": "^20.1.3",
43
43
  "@hapi/inert": "^6.0.3",
@@ -52,5 +52,5 @@
52
52
  "moment-timezone": "^0.5.34",
53
53
  "uuid": "^8.3.2"
54
54
  },
55
- "gitHead": "0c8e398672b3e85316a93115385d40c2412048b9"
55
+ "gitHead": "94d567772c93817f97bdd6226f9f845e093a4e03"
56
56
  }
@@ -18,7 +18,7 @@ describe('createTransactionSchema', () => {
18
18
 
19
19
  it('validates successfully when issueDate and startDate are null', async () => {
20
20
  const mockPayload = mockTransactionPayload()
21
- mockPayload.permissions.map(p => ({ ...p, issueDate: null, startDate: null }))
21
+ mockPayload.permissions = mockPayload.permissions.map(p => ({ ...p, issueDate: null, startDate: null }))
22
22
  const result = await createTransactionSchema.validateAsync(mockPayload)
23
23
  expect(result).toBeInstanceOf(Object)
24
24
  })
@@ -70,6 +70,31 @@ describe('createTransactionSchema', () => {
70
70
  mockPayload.permissions[0].isLicenceForYou = 'test'
71
71
  await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow('"permissions[0].isLicenceForYou" must be a boolean')
72
72
  })
73
+
74
+ it('validates successfully when a uuid v4 transaction id is supplied', async () => {
75
+ const mockPayload = mockTransactionPayload()
76
+ mockPayload.transactionId = '25fa0126-55da-4309-9bce-9957990d141e'
77
+ await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
78
+ })
79
+
80
+ it('validates successfully when transactionId is omitted', async () => {
81
+ const mockPayload = mockTransactionPayload()
82
+ await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
83
+ })
84
+
85
+ it.each([
86
+ ['uuid1 string', '5a429f62-871b-11ef-b864-0242ac120002'],
87
+ ['uuid2 string', '000003e8-871b-21ef-8000-325096b39f47'],
88
+ ['uuid3 string', 'a3bb189e-8bf9-3888-9912-ace4e6543002'],
89
+ ['uuid5 string', 'a6edc906-2f9f-5fb2-a373-efac406f0ef2'],
90
+ ['uuid6 string', 'a3bb189e-8bf9-3888-9912-ace4e6543002'],
91
+ ['uuid7 string', '01927705-ffac-77b5-89af-c97451b1bbe2'],
92
+ ['numeric', 4567]
93
+ ])('fails validation when provided with a %s', async (_d, transactionId) => {
94
+ const mockPayload = mockTransactionPayload()
95
+ mockPayload.transactionId = transactionId
96
+ await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
97
+ })
73
98
  })
74
99
 
75
100
  describe('createTransactionResponseSchema', () => {
@@ -32,7 +32,8 @@ const createTransactionRequestSchemaContent = {
32
32
  then: Joi.string().trim().min(1).required()
33
33
  }),
34
34
  createdBy: Joi.string().optional(),
35
- journalId: Joi.string().optional()
35
+ journalId: Joi.string().optional(),
36
+ transactionId: Joi.string().guid({ version: 'uuidv4' })
36
37
  }
37
38
 
38
39
  /**
@@ -77,6 +77,13 @@ describe('transaction service', () => {
77
77
  AwsMock.DynamoDB.DocumentClient.__throwWithErrorOn('put')
78
78
  await expect(createTransaction(mockTransactionPayload())).rejects.toThrow('Test error')
79
79
  })
80
+
81
+ it('uses transaction id if supplied in payload', async () => {
82
+ const mockPayload = mockTransactionPayload()
83
+ mockPayload.transactionId = 'abc-123-def-456'
84
+ const result = await createTransaction(mockPayload)
85
+ expect(result.id).toBe(mockPayload.transactionId)
86
+ })
80
87
  })
81
88
 
82
89
  describe('createTransactions', () => {
@@ -48,7 +48,7 @@ export async function createTransactions (payload) {
48
48
  * @returns {Promise<*>}
49
49
  */
50
50
  async function createTransactionRecord (payload) {
51
- const transactionId = uuidv4()
51
+ const transactionId = payload.transactionId || uuidv4()
52
52
  debug('Creating new transaction %s for %s', transactionId, payload.dataSource)
53
53
  const record = {
54
54
  id: transactionId,