@defra-fish/pocl-job 1.64.0-rc.2 → 1.64.0-rc.4

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.64.0-rc.2",
3
+ "version": "1.64.0-rc.4",
4
4
  "description": "Post Office Counter Licence sales processor",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,15 +35,15 @@
35
35
  "test": "echo \"Error: run tests from root\" && exit 1"
36
36
  },
37
37
  "dependencies": {
38
- "@defra-fish/business-rules-lib": "1.64.0-rc.2",
39
- "@defra-fish/connectors-lib": "1.64.0-rc.2",
40
- "commander": "^7.2.0",
41
- "debug": "^4.3.3",
42
- "filesize": "^6.4.0",
43
- "md5-file": "^5.0.0",
44
- "moment": "^2.29.1",
45
- "moment-timezone": "^0.5.34",
46
- "sax-stream": "^1.3.0"
38
+ "@defra-fish/business-rules-lib": "1.64.0-rc.4",
39
+ "@defra-fish/connectors-lib": "1.64.0-rc.4",
40
+ "commander": "7.2.0",
41
+ "debug": "4.3.3",
42
+ "filesize": "6.4.0",
43
+ "md5-file": "5.0.0",
44
+ "moment": "2.29.1",
45
+ "moment-timezone": "0.5.34",
46
+ "sax-stream": "1.3.0"
47
47
  },
48
- "gitHead": "b901cb67affda78c747af57f88753b8039bd2172"
48
+ "gitHead": "76c74f746d5ab23a1f8043f7e1445eeb60bb5a8e"
49
49
  }
@@ -54,7 +54,7 @@
54
54
  <START_TIME>15:00</START_TIME>
55
55
  <CHANNEL_ID>67236X</CHANNEL_ID>
56
56
  <SERIAL_NO>SERIAL 1</SERIAL_NO>
57
- <AMOUNT>54</AMOUNT>
57
+ <AMOUNT>60.2</AMOUNT>
58
58
  <MOPEX>2</MOPEX>
59
59
  <SYSTEM_DATE>01/01/2020</SYSTEM_DATE>
60
60
  <SYSTEM_TIME>13:00:00</SYSTEM_TIME>
@@ -108,7 +108,7 @@
108
108
  <START_TIME>15:00</START_TIME>
109
109
  <CHANNEL_ID>21995X</CHANNEL_ID>
110
110
  <SERIAL_NO>SERIAL 2</SERIAL_NO>
111
- <AMOUNT>82</AMOUNT>
111
+ <AMOUNT>90.4</AMOUNT>
112
112
  <MOPEX>3</MOPEX>
113
113
  <SYSTEM_DATE>01/07/2020</SYSTEM_DATE>
114
114
  <SYSTEM_TIME>13:00:00</SYSTEM_TIME>
@@ -36,7 +36,7 @@ Object {
36
36
  },
37
37
  "finaliseTransactionPayload": Object {
38
38
  "payment": Object {
39
- "amount": 82,
39
+ "amount": 90.4,
40
40
  "channelId": "21995X",
41
41
  "method": "Stamps",
42
42
  "source": "Post Office Sales",
@@ -1,15 +1,13 @@
1
1
  import { s3ToLocal } from '../s3-to-local.js'
2
- import stream from 'stream'
2
+ import { Readable } from 'stream'
3
3
  import { AWS } from '@defra-fish/connectors-lib'
4
4
  import fs from 'fs'
5
- const { s3 } = AWS.mock.results[0].value
6
5
 
7
6
  const MOCK_TMP = '/tmp/local/mock'
8
- jest.mock('stream')
7
+
9
8
  jest.mock('../../io/file.js', () => ({
10
9
  getTempDir: jest.fn((...subfolders) => `${MOCK_TMP}/${subfolders.join('/')}`)
11
10
  }))
12
-
13
11
  jest.mock('../../config.js', () => ({
14
12
  s3: {
15
13
  bucket: 'testbucket'
@@ -19,35 +17,51 @@ jest.mock('../../config.js', () => ({
19
17
  jest.mock('@defra-fish/connectors-lib', () => ({
20
18
  AWS: jest.fn(() => ({
21
19
  s3: {
22
- getObject: jest.fn(() => ({
23
- createReadStream: jest.fn(() => ({}))
24
- }))
25
- }
20
+ send: jest.fn()
21
+ },
22
+ GetObjectCommand: jest.fn(params => ({ ...params }))
26
23
  }))
27
24
  }))
28
25
 
26
+ jest.mock('util', () => {
27
+ const actualUtil = jest.requireActual('util')
28
+ return {
29
+ ...actualUtil,
30
+ promisify: jest.fn(() => {
31
+ return jest.fn(() => Promise.resolve())
32
+ })
33
+ }
34
+ })
35
+
29
36
  describe('s3-to-local', () => {
37
+ const { s3 } = AWS.mock.results[0].value
38
+
30
39
  beforeEach(() => {
31
40
  jest.clearAllMocks()
32
41
  })
33
42
 
34
43
  it('retrieves a file from s3 for a given key', async () => {
35
- jest.spyOn(fs, 'createWriteStream').mockReturnValueOnce({})
36
- stream.pipeline.mockImplementation(
37
- jest.fn((streams, callback) => {
38
- callback()
39
- })
40
- )
44
+ const mockStream = new Readable({
45
+ read () {
46
+ this.push('test data')
47
+ this.push(null)
48
+ }
49
+ })
50
+
51
+ s3.send.mockResolvedValue({ Body: mockStream })
52
+
53
+ jest.spyOn(fs, 'createWriteStream').mockReturnValue({})
41
54
 
42
- const result = await s3ToLocal('/example/testS3Key.xml')
43
- const { createReadStream } = s3.getObject.mock.results[0].value
55
+ const s3Key = '/example/testS3Key.xml'
56
+ const result = await s3ToLocal(s3Key)
44
57
 
45
58
  expect(result).toBe(`${MOCK_TMP}/example/testS3Key.xml`)
46
- expect(createReadStream).toHaveBeenCalled()
47
- expect(stream.pipeline).toHaveBeenCalled()
48
- expect(s3.getObject).toHaveBeenCalledWith({
49
- Bucket: 'testbucket',
50
- Key: '/example/testS3Key.xml'
51
- })
59
+ expect(fs.createWriteStream).toHaveBeenCalledWith(`${MOCK_TMP}/example/testS3Key.xml`)
60
+ expect(s3.send).toHaveBeenCalledWith(
61
+ expect.objectContaining({
62
+ Bucket: 'testbucket',
63
+ Key: s3Key
64
+ })
65
+ )
52
66
  })
53
67
  })
@@ -6,15 +6,21 @@ import db from 'debug'
6
6
  import config from '../config.js'
7
7
  import { getTempDir } from '../io/file.js'
8
8
  import { AWS } from '@defra-fish/connectors-lib'
9
+
9
10
  const pipeline = util.promisify(stream.pipeline)
10
- const { s3 } = AWS()
11
+ const { s3, GetObjectCommand } = AWS()
11
12
  const debug = db('pocl:transport')
12
13
 
13
14
  export async function s3ToLocal (s3Key) {
14
15
  debug('Transferring %s to the local storage', s3Key)
15
16
  const localPath = Path.join(getTempDir(Path.dirname(s3Key)), Path.basename(s3Key))
16
17
  const localWriteStream = fs.createWriteStream(localPath)
17
- const s3ReadStream = s3.getObject({ Bucket: config.s3.bucket, Key: s3Key }).createReadStream()
18
- await pipeline([s3ReadStream, localWriteStream])
18
+ const { Body } = await s3.send(
19
+ new GetObjectCommand({
20
+ Bucket: config.s3.bucket,
21
+ Key: s3Key
22
+ })
23
+ )
24
+ await pipeline(Body, localWriteStream)
19
25
  return localPath
20
26
  }