-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from lebanon-relief-project/dev
Dev
- Loading branch information
Showing
8 changed files
with
131 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const mockEnvironmentVars = { | ||
"cloud-object-storage": [ | ||
{ | ||
"instance_name": "MOCK_COS", | ||
"credentials": { | ||
"apikey": "mockapikey", | ||
"cos_hmac_keys": { | ||
"access_key_id": "mockaccesskeyid", | ||
"secret_access_key": "mocksecretaccesskey" | ||
}, | ||
"endpoints": "mockendpoint", | ||
"iam_apikey_description": "mockapikeydescription", | ||
"iam_apikey_name": "mockapikeyname", | ||
"iam_role_crn": "mockiamrole", | ||
"iam_serviceid_crn": "mockserviceidcrn", | ||
"resource_instance_id": "mockresourceinstanceid" | ||
} | ||
} | ||
] | ||
} | ||
|
||
export const mockEnvironmentVarsTrailingSpaces = { | ||
"cloud-object-storage": [ | ||
{ | ||
"instance_name": "MOCK_COS", | ||
"credentials": { | ||
"apikey": "mockapikey ", | ||
"cos_hmac_keys": { | ||
"access_key_id": "mockaccesskeyid ", | ||
"secret_access_key": "mocksecretaccesskey " | ||
}, | ||
"endpoints": "mockendpoint ", | ||
"iam_apikey_description": "mockapikeydescription ", | ||
"iam_apikey_name": "mockapikeyname ", | ||
"iam_role_crn": "mockiamrole ", | ||
"iam_serviceid_crn": "mockserviceidcrn ", | ||
"resource_instance_id": "mockresourceinstanceid " | ||
} | ||
} | ||
] | ||
} | ||
|
||
|
||
export const mockEnvironmentVarsMissing = { | ||
"cloud-object-storage": [ | ||
] | ||
} |
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,54 @@ | ||
import { mockEnvironmentVars, mockEnvironmentVarsTrailingSpaces, mockEnvironmentVarsMissing } from '../types/sampleData/CosCredsSampleData'; | ||
import { getCosCredentials } from "./cosCreds"; | ||
import { COS_URL } from "../statics"; | ||
|
||
|
||
const mockConsoleError = jest.spyOn(global.console, 'error').mockImplementation(() => {}); | ||
|
||
describe("getCosCredentials function testing", () => { | ||
const env = process.env | ||
|
||
beforeEach(() => { | ||
jest.resetModules() | ||
process.env = { ...env } | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = env | ||
}) | ||
|
||
it("should return CosCredentials from env", () =>{ | ||
process.env.VCAP_SERVICES = JSON.stringify(mockEnvironmentVars); | ||
let envVars = getCosCredentials(); | ||
expect(envVars).toStrictEqual({ | ||
endpoint: COS_URL, | ||
apiKeyId: mockEnvironmentVars["cloud-object-storage"][0].credentials.apikey, | ||
serviceInstanceId: mockEnvironmentVars["cloud-object-storage"][0].credentials.resource_instance_id, | ||
signatureVersion: "v4", | ||
accessKeyId: mockEnvironmentVars["cloud-object-storage"][0].credentials.cos_hmac_keys.access_key_id, | ||
secretAccessKey: mockEnvironmentVars["cloud-object-storage"][0].credentials.cos_hmac_keys.secret_access_key, | ||
}); | ||
}); | ||
|
||
it("should clean trailing spaces from CosCredentials", () => { | ||
process.env.VCAP_SERVICES = JSON.stringify(mockEnvironmentVarsTrailingSpaces); | ||
let envVars = getCosCredentials(); | ||
expect(envVars).toStrictEqual({ | ||
endpoint: COS_URL, | ||
apiKeyId: mockEnvironmentVars["cloud-object-storage"][0].credentials.apikey, | ||
serviceInstanceId: mockEnvironmentVars["cloud-object-storage"][0].credentials.resource_instance_id, | ||
signatureVersion: "v4", | ||
accessKeyId: mockEnvironmentVars["cloud-object-storage"][0].credentials.cos_hmac_keys.access_key_id, | ||
secretAccessKey: mockEnvironmentVars["cloud-object-storage"][0].credentials.cos_hmac_keys.secret_access_key, | ||
}); | ||
}) | ||
|
||
it("should call console error if env vars are missing", () => { | ||
process.env.VCAP_SERVICES = JSON.stringify(mockEnvironmentVarsMissing) | ||
|
||
getCosCredentials(); | ||
|
||
expect(mockConsoleError).toHaveBeenCalledTimes(1) | ||
}); | ||
}) | ||
|
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
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