generated from DEFRA/ffc-template-node
-
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.
Commiting changes for v10 pipeline migration (#46)
* Commiting changes for v10 pipeline migration * update package-lock.json * 1.3.20 * Alterations to storage.test.js * Changing storage unit tests * Standard js fixes --------- Co-authored-by: ffcplatform <ffcplatforms@environment-agency.gov.uk>
- Loading branch information
1 parent
7f38c31
commit 0f8f6bb
Showing
22 changed files
with
125 additions
and
65 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
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 @@ | ||
container.alertTopicAddress: queue:ffc-pay-alert |
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-alerting.service-account") -}} | ||
{{- define "ffc-pay-alerting.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,3 +1,7 @@ | ||
resources: | ||
identity: pay-alerting | ||
topics: | ||
- name: alert | ||
- name: ffc-pay-alert | ||
role: receiver | ||
subscriptions: | ||
- name: ffc-pay-alerting |
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 |
---|---|---|
@@ -1,43 +1,98 @@ | ||
const { getInboundBlobClient, blobServiceClient } = require('../../app/storage') | ||
const config = require('../../app/config').storageConfig | ||
|
||
jest.mock('@azure/storage-blob', () => { | ||
const mBlobServiceClient = { | ||
getContainerClient: jest.fn().mockReturnThis(), | ||
getBlockBlobClient: jest.fn().mockReturnThis(), | ||
upload: jest.fn().mockResolvedValue(true), | ||
createIfNotExists: jest.fn().mockResolvedValue(true) | ||
jest.mock('@azure/storage-blob') | ||
jest.mock('@azure/identity') | ||
|
||
describe('storage', () => { | ||
let storage | ||
const mockstorage = { | ||
upload: jest.fn().mockResolvedValue({}), | ||
url: 'test-url' | ||
} | ||
return { | ||
BlobServiceClient: { | ||
fromConnectionString: jest.fn(() => mBlobServiceClient) | ||
}, | ||
ContainerClient: jest.fn(() => mBlobServiceClient), | ||
BlockBlobClient: jest.fn(() => mBlobServiceClient) | ||
|
||
const mockContainer = { | ||
createIfNotExists: jest.fn(), | ||
getBlockBlobClient: jest.fn().mockReturnValue(mockstorage) | ||
} | ||
|
||
const mockStorageConfig = { | ||
useConnectionStr: true, | ||
connectionStr: 'connection-string', | ||
createContainers: true, | ||
storageAccount: 'fakestorageaccount', | ||
managedIdentityClientId: 'fake-client-id', | ||
container: 'test-container', | ||
inboundFolder: 'test-folder' | ||
} | ||
|
||
const mockBlobServiceClient = { | ||
getContainerClient: jest.fn().mockReturnValue(mockContainer) | ||
} | ||
}) | ||
|
||
describe('Azure Blob Storage Module', () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
jest.clearAllMocks() | ||
|
||
require('@azure/storage-blob').BlobServiceClient.fromConnectionString = jest | ||
.fn() | ||
.mockReturnValue(mockBlobServiceClient) | ||
|
||
require('@azure/storage-blob').BlobServiceClient.mockImplementation(() => mockBlobServiceClient) | ||
|
||
require('@azure/identity').DefaultAzureCredential.mockImplementation(() => ({})) | ||
|
||
jest.mock('../../app/config', () => ({ | ||
storageConfig: mockStorageConfig | ||
})) | ||
|
||
storage = require('../../app/storage') | ||
}) | ||
|
||
test('uses connection string when config.useConnectionStr is true', async () => { | ||
expect(require('@azure/storage-blob').BlobServiceClient.fromConnectionString) | ||
.toHaveBeenCalledWith(mockStorageConfig.connectionStr) | ||
}) | ||
|
||
test('should initialize containers and folders', async () => { | ||
const containerClient = blobServiceClient.getContainerClient(config.container) | ||
await containerClient.createIfNotExists() | ||
expect(containerClient.createIfNotExists).toHaveBeenCalled() | ||
test('uses DefaultAzureCredential when config.useConnectionStr is false', async () => { | ||
jest.resetModules() | ||
mockStorageConfig.useConnectionStr = false | ||
|
||
jest.mock('../../app/config', () => ({ | ||
storageConfig: mockStorageConfig | ||
})) | ||
|
||
storage = require('../../app/storage') | ||
|
||
expect(require('@azure/identity').DefaultAzureCredential).toHaveBeenCalledWith({ | ||
managedIdentityClientId: 'fake-client-id' | ||
}) | ||
|
||
expect(require('@azure/storage-blob').BlobServiceClient).toHaveBeenCalledWith( | ||
`https://${mockStorageConfig.storageAccount}.blob.core.windows.net`, | ||
expect.any(Object) | ||
) | ||
}) | ||
|
||
test('should upload placeholder files to folders', async () => { | ||
const containerClient = blobServiceClient.getContainerClient(config.container) | ||
const blockBlobClient = containerClient.getBlockBlobClient(`${config.inboundFolder}/default.txt`) | ||
await blockBlobClient.upload('Placeholder', 'Placeholder'.length) | ||
expect(blockBlobClient.upload).toHaveBeenCalledWith('Placeholder', 'Placeholder'.length) | ||
test('gets outbound blob client', async () => { | ||
const result = await storage.getInboundBlobClient('test-file.txt') | ||
expect(result.url).toBe('test-url') | ||
expect(mockContainer.getBlockBlobClient).toHaveBeenCalledWith('test-folder/test-file.txt') | ||
}) | ||
|
||
test('should return the correct blob client for inbound folder', async () => { | ||
const blobClient = await getInboundBlobClient('testfile.txt') | ||
expect(blobClient).toBeDefined() | ||
expect(blobClient.upload).toBeDefined() | ||
describe('when using managed identity', () => { | ||
test('creates blob service client with DefaultAzureCredential', () => { | ||
jest.resetModules() | ||
mockStorageConfig.useConnectionStr = false | ||
|
||
jest.mock('../../app/config', () => ({ | ||
storageConfig: mockStorageConfig | ||
})) | ||
|
||
require('../../app/storage') | ||
|
||
expect(require('@azure/storage-blob').BlobServiceClient) | ||
.toHaveBeenCalledWith( | ||
`https://${mockStorageConfig.storageAccount}.blob.core.windows.net`, | ||
expect.any(Object) | ||
) | ||
}) | ||
}) | ||
}) |