@defra-fish/pocl-job 1.64.0-rc.2 → 1.64.0-rc.3
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.
|
|
3
|
+
"version": "1.64.0-rc.3",
|
|
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.64.0-rc.
|
|
39
|
-
"@defra-fish/connectors-lib": "1.64.0-rc.
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.64.0-rc.3",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.64.0-rc.3",
|
|
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": "
|
|
48
|
+
"gitHead": "709cc3d3ded64bf33d0c68bfd7484c829a226ab2"
|
|
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>
|
|
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>
|
|
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>
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { s3ToLocal } from '../s3-to-local.js'
|
|
2
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
43
|
-
const
|
|
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(
|
|
47
|
-
expect(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
18
|
-
|
|
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
|
}
|