-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migration to V10 Pipeline * bumpity bump * changed container names * removing subscription address * helm chart bump * provision file update * npm audit fix * storage test * actually include file * MiD on table storage
- Loading branch information
1 parent
fb230a0
commit 050e399
Showing
24 changed files
with
194 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
@Library('defra-library@v-9') _ | ||
@Library('defra-library@v-10') _ | ||
|
||
buildNodeJs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
const { getEventOrder } = require('./get-event-order') | ||
|
||
const orderGroupedEvents = (events) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
const orderGroupedEventsByScheme = (events) => { | ||
return events.sort((a, b) => a.schemeId - b.schemeId) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
container.dataResponseQueueAddress: queue:ffc-pay-data-request-response | ||
container.dataTopicAddress: queue:ffc-pay-data-request |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{- include "ffc-helm-library.service-account" (list . "ffc-pay-data-hub.service-account") -}} | ||
{{- define "ffc-pay-data-hub.service-account" -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
resources: | ||
identity: pay-data-hub | ||
topics: | ||
- name: data | ||
- name: ffc-pay-data-request | ||
role: receiver | ||
subscriptions: | ||
-name: ffc-pay-data-hub | ||
queues: | ||
- name: dataResponse | ||
enableSessions: true | ||
- name: ffc-pay-data-request-response | ||
role: sender | ||
session: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
sonar.javascript.exclusions=**/jest.config.js,**/__mocks__/**,**/node_modules/**,**/test/**,**/test-output/** | ||
sonar.javascript.exclusions=**/jest.config.js,**/__mocks__/**,**/node_modules/**,**/test/**,**/test-output/**,**/app/config/** | ||
sonar.javascript.lcov.reportPaths=test-output/lcov.info | ||
sonar.exclusions=/test/**,**/*.test.js,*snyk_report.html,*snyk_report.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
const { PAYMENT_EVENT, HOLD_EVENT, WARNING_EVENT, BATCH_EVENT } = require('../../app/constants/event-types') | ||
|
||
describe('Storage initialization and functionality', () => { | ||
let consoleLogSpy | ||
let storageConfig | ||
let BlobServiceClient | ||
let DefaultAzureCredential | ||
let TableClient | ||
let storage | ||
|
||
beforeAll(() => { | ||
jest.doMock('@azure/storage-blob', () => { | ||
const getBlockBlobClientMock = jest.fn().mockReturnValue({ | ||
upload: jest.fn().mockResolvedValue() | ||
}) | ||
const getContainerClientMock = jest.fn().mockReturnValue({ | ||
createIfNotExists: jest.fn().mockResolvedValue(), | ||
getBlockBlobClient: getBlockBlobClientMock | ||
}) | ||
const fromConnectionStringMock = jest.fn().mockReturnValue({ | ||
getContainerClient: getContainerClientMock | ||
}) | ||
const BlobServiceClientMock = jest.fn().mockImplementation(() => ({ | ||
getContainerClient: getContainerClientMock | ||
})) | ||
BlobServiceClientMock.fromConnectionString = fromConnectionStringMock | ||
return { BlobServiceClient: BlobServiceClientMock } | ||
}) | ||
|
||
jest.doMock('@azure/identity', () => ({ | ||
DefaultAzureCredential: jest.fn().mockImplementation((options) => ({ | ||
type: 'DefaultAzureCredential', | ||
options | ||
})) | ||
})) | ||
|
||
jest.doMock('@azure/data-tables', () => { | ||
const createTableMock = jest.fn().mockResolvedValue() | ||
const TableClientMock = jest.fn().mockImplementation(() => ({ | ||
createTable: createTableMock | ||
})) | ||
TableClientMock.fromConnectionString = jest.fn().mockReturnValue({ | ||
createTable: createTableMock | ||
}) | ||
return { TableClient: TableClientMock, odata: {} } | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.resetModules() | ||
jest.clearAllMocks() | ||
|
||
storageConfig = require('../../app/config/storage') | ||
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => { }) | ||
; ({ BlobServiceClient } = require('@azure/storage-blob')) | ||
; ({ DefaultAzureCredential } = require('@azure/identity')) | ||
; ({ TableClient } = require('@azure/data-tables')) | ||
storage = require('../../app/storage') | ||
}) | ||
|
||
afterEach(() => { | ||
consoleLogSpy.mockRestore() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test('should use connection string when storageConfig.useConnectionString is true', async () => { | ||
storageConfig.useConnectionString = true | ||
storageConfig.connectionString = 'fake-connection-string' | ||
|
||
await storage.initialise() | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith('Using connection string for Table Client') | ||
expect(BlobServiceClient.fromConnectionString).toHaveBeenCalledWith(storageConfig.connectionString) | ||
expect(TableClient.fromConnectionString).toHaveBeenCalledTimes(4) | ||
}) | ||
|
||
test('should use DefaultAzureCredential when storageConfig.useConnectionString is false', async () => { | ||
storageConfig.useConnectionString = false | ||
storageConfig.account = 'fakeaccount' | ||
storageConfig.storageAccount = 'fakestorageaccount' | ||
storageConfig.managedIdentityClientId = 'fake-managed-id' | ||
|
||
await storage.initialise() | ||
|
||
const expectedBlobUri = `https://${storageConfig.storageAccount}.blob.core.windows.net` | ||
const expectedTableUri = `https://${storageConfig.account}.table.core.windows.net` | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith('Using DefaultAzureCredential for Table Client') | ||
expect(DefaultAzureCredential).toHaveBeenCalledWith({ managedIdentityClientId: storageConfig.managedIdentityClientId }) | ||
expect(BlobServiceClient).toHaveBeenCalledWith(expectedBlobUri, expect.any(Object)) | ||
expect(TableClient).toHaveBeenCalledTimes(4) | ||
expect(TableClient).toHaveBeenCalledWith(expectedTableUri, expect.any(String), expect.any(Object)) | ||
}) | ||
|
||
test('should create tables and container when createEntities is true', async () => { | ||
storageConfig.createEntities = true | ||
storageConfig.useConnectionString = true | ||
storageConfig.connectionString = 'fake-connection-string' | ||
|
||
await storage.initialise() | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith('Making sure tables exist') | ||
expect(consoleLogSpy).toHaveBeenCalledWith('Making sure blob containers exist') | ||
expect(consoleLogSpy).toHaveBeenCalledWith('Storage ready') | ||
expect(TableClient.fromConnectionString().createTable).toHaveBeenCalledTimes(4) | ||
expect(BlobServiceClient.fromConnectionString().getContainerClient().createIfNotExists).toHaveBeenCalled() | ||
}) | ||
|
||
test('should return correct client based on event type', async () => { | ||
await storage.initialise() | ||
|
||
const paymentClient = storage.getClient(PAYMENT_EVENT) | ||
const holdClient = storage.getClient(HOLD_EVENT) | ||
const warningClient = storage.getClient(WARNING_EVENT) | ||
const batchClient = storage.getClient(BATCH_EVENT) | ||
|
||
expect(paymentClient).toBeDefined() | ||
expect(holdClient).toBeDefined() | ||
expect(warningClient).toBeDefined() | ||
expect(batchClient).toBeDefined() | ||
}) | ||
|
||
test('should throw error for unknown event type', async () => { | ||
await storage.initialise() | ||
|
||
expect(() => storage.getClient('UNKNOWN_EVENT')).toThrow('Unknown event type: UNKNOWN_EVENT') | ||
}) | ||
|
||
test('should write file to blob storage', async () => { | ||
await storage.initialise() | ||
|
||
const filename = 'test.txt' | ||
const content = 'Hello, World!' | ||
|
||
await storage.writeFile(filename, content) | ||
|
||
const containerClient = BlobServiceClient.fromConnectionString().getContainerClient() | ||
expect(containerClient.getBlockBlobClient).toHaveBeenCalledWith(filename) | ||
expect(containerClient.getBlockBlobClient().upload).toHaveBeenCalledWith(content, content.length) | ||
}) | ||
}) |