@defra-fish/pocl-job 1.61.0-rc.16 → 1.61.0-rc.18

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/pocl-job",
3
- "version": "1.61.0-rc.16",
3
+ "version": "1.61.0-rc.18",
4
4
  "description": "Post Office Counter Licence sales processor",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,8 +35,8 @@
35
35
  "test": "echo \"Error: run tests from root\" && exit 1"
36
36
  },
37
37
  "dependencies": {
38
- "@defra-fish/business-rules-lib": "1.61.0-rc.16",
39
- "@defra-fish/connectors-lib": "1.61.0-rc.16",
38
+ "@defra-fish/business-rules-lib": "1.61.0-rc.18",
39
+ "@defra-fish/connectors-lib": "1.61.0-rc.18",
40
40
  "commander": "^7.2.0",
41
41
  "debug": "^4.3.3",
42
42
  "filesize": "^6.4.0",
@@ -45,5 +45,5 @@
45
45
  "moment-timezone": "^0.5.34",
46
46
  "sax-stream": "^1.3.0"
47
47
  },
48
- "gitHead": "a4d24d55c8279ed8fad6436a48312f8542adfada"
48
+ "gitHead": "e6a140250c115a25e37da3f1639e83df2e6ca886"
49
49
  }
@@ -4,7 +4,7 @@ import { updateFileStagingTable } from '../../io/db.js'
4
4
  import { DYNAMICS_IMPORT_STAGE, FILE_STAGE, POST_OFFICE_DATASOURCE } from '../../staging/constants.js'
5
5
  import { salesApi, AWS } from '@defra-fish/connectors-lib'
6
6
  import fs from 'fs'
7
- const { s3 } = AWS.mock.results[0].value
7
+ const { s3, ListObjectsV2Command } = AWS.mock.results[0].value
8
8
 
9
9
  jest.mock('md5-file')
10
10
  jest.mock('../../io/db.js')
@@ -18,13 +18,12 @@ jest.mock('@defra-fish/connectors-lib', () => {
18
18
  createUpdateExpression: jest.fn(() => ({}))
19
19
  },
20
20
  s3: {
21
- listObjectsV2: jest.fn(() => ({
22
- Contents: []
23
- })),
24
21
  getObject: jest.fn(() => ({
25
22
  createReadStream: jest.fn()
26
- }))
27
- }
23
+ })),
24
+ send: jest.fn()
25
+ },
26
+ ListObjectsV2Command: jest.fn()
28
27
  }))
29
28
  return {
30
29
  AWS,
@@ -54,7 +53,7 @@ describe('s3 operations', () => {
54
53
  const s3Key2 = `${moment().format('YYYY-MM-DD')}/test2.xml`
55
54
 
56
55
  beforeEach(async () => {
57
- s3.listObjectsV2.mockReturnValueOnce({
56
+ s3.send.mockReturnValueOnce({
58
57
  IsTruncated: false,
59
58
  Contents: [
60
59
  {
@@ -75,8 +74,8 @@ describe('s3 operations', () => {
75
74
  await refreshS3Metadata()
76
75
  })
77
76
 
78
- it('calls listObjectsV2, with bucket name and no continuation token', () => {
79
- expect(s3.listObjectsV2).toHaveBeenNthCalledWith(1, {
77
+ it('calls ListObjectsV2Command, with bucket name and no continuation token', () => {
78
+ expect(ListObjectsV2Command).toHaveBeenNthCalledWith(1, {
80
79
  Bucket: 'testbucket',
81
80
  ContinuationToken: undefined
82
81
  })
@@ -129,7 +128,7 @@ describe('s3 operations', () => {
129
128
  const s3Key1 = `${moment().format('YYYY-MM-DD')}/test1.xml`
130
129
 
131
130
  beforeEach(async () => {
132
- s3.listObjectsV2
131
+ s3.send
133
132
  .mockReturnValue({
134
133
  IsTruncated: false,
135
134
  Contents: [
@@ -157,15 +156,15 @@ describe('s3 operations', () => {
157
156
  await refreshS3Metadata()
158
157
  })
159
158
 
160
- it('calls listObjectsV2 a first time with bucket name and no continuation token', () => {
161
- expect(s3.listObjectsV2).toHaveBeenNthCalledWith(1, {
159
+ it('calls ListObjectsV2Command a first time with bucket name and no continuation token', () => {
160
+ expect(ListObjectsV2Command).toHaveBeenNthCalledWith(1, {
162
161
  Bucket: 'testbucket',
163
162
  ContinuationToken: undefined
164
163
  })
165
164
  })
166
165
 
167
- it('calls listObjectsV2 a second time with bucket name and continuation token', () => {
168
- expect(s3.listObjectsV2).toHaveBeenNthCalledWith(2, {
166
+ it('calls ListObjectsV2Command a second time with bucket name and continuation token', () => {
167
+ expect(ListObjectsV2Command).toHaveBeenNthCalledWith(2, {
169
168
  Bucket: 'testbucket',
170
169
  ContinuationToken: 'token'
171
170
  })
@@ -209,7 +208,7 @@ describe('s3 operations', () => {
209
208
  salesApi.getTransactionFile.mockResolvedValueOnce({ status: { description: 'Processed' } })
210
209
  const s3Key = `${moment().format('YYYY-MM-DD')}/test-already-processed.xml`
211
210
 
212
- s3.listObjectsV2.mockReturnValueOnce({
211
+ s3.send.mockReturnValueOnce({
213
212
  IsTruncated: false,
214
213
  Contents: [
215
214
  {
@@ -230,7 +229,7 @@ describe('s3 operations', () => {
230
229
  it('skips file processing if a file is older than one week', async () => {
231
230
  const s3Key1 = `${moment().format('YYYY-MM-DD')}/test1.xml`
232
231
 
233
- s3.listObjectsV2
232
+ s3.send
234
233
  .mockReturnValue({
235
234
  IsTruncated: false,
236
235
  Contents: [
@@ -261,11 +260,11 @@ describe('s3 operations', () => {
261
260
  expect(salesApi.upsertTransactionFile).not.toHaveBeenCalled()
262
261
  })
263
262
 
264
- it('logs any errors raised by calling s3.listObjectsV2', async () => {
263
+ it('logs any errors raised by calling ListObjectsV2Command', async () => {
265
264
  const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
266
265
 
267
266
  const testError = new Error('Test error')
268
- s3.listObjectsV2.mockRejectedValueOnce(testError)
267
+ s3.send.mockRejectedValueOnce(testError)
269
268
 
270
269
  await expect(refreshS3Metadata()).rejects.toThrow(testError)
271
270
  expect(consoleErrorSpy).toHaveBeenCalledWith(testError)
@@ -274,7 +273,7 @@ describe('s3 operations', () => {
274
273
  it('raises a warning if the bucket is empty', async () => {
275
274
  const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
276
275
 
277
- s3.listObjectsV2.mockReturnValueOnce({
276
+ s3.send.mockReturnValueOnce({
278
277
  IsTruncated: false
279
278
  })
280
279
 
package/src/io/s3.js CHANGED
@@ -4,11 +4,12 @@ import config from '../config.js'
4
4
  import { DYNAMICS_IMPORT_STAGE } from '../staging/constants.js'
5
5
  import { storeS3Metadata } from '../transport/storeS3MetaData.js'
6
6
  import { AWS, salesApi } from '@defra-fish/connectors-lib'
7
- const { s3 } = AWS()
7
+ const { s3, ListObjectsV2Command } = AWS()
8
8
 
9
9
  const listObjectsV2 = async function (params) {
10
10
  try {
11
- return await s3.listObjectsV2(params)
11
+ const command = new ListObjectsV2Command(params)
12
+ return await s3.send(command)
12
13
  } catch (e) {
13
14
  console.error(e)
14
15
  throw e