Skip to content

Commit

Permalink
Merge pull request #223 from lebanon-relief-project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
matejoslav authored Jul 2, 2022
2 parents 1890736 + b7c4029 commit 0e9e3be
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 7 deletions.
47 changes: 47 additions & 0 deletions src/types/sampleData/CosCredsSampleData.ts
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": [
]
}
54 changes: 54 additions & 0 deletions src/util/cosCreds.spec.ts
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)
});
})

8 changes: 4 additions & 4 deletions src/util/cosCreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export function getCosCredentials(): CosCredentials {

try {
endpoint = COS_URL;
apikey = VCAP["cloud-object-storage"][0].credentials.apikey;
resourceInstanceId = VCAP["cloud-object-storage"][0].credentials.resource_instance_id;
accessKeyId = VCAP["cloud-object-storage"][0].credentials.cos_hmac_keys.access_key_id;
secretAccessKey = VCAP["cloud-object-storage"][0].credentials.cos_hmac_keys.secret_access_key;
apikey = VCAP["cloud-object-storage"][0].credentials.apikey.trim();
resourceInstanceId = VCAP["cloud-object-storage"][0].credentials.resource_instance_id.trim();
accessKeyId = VCAP["cloud-object-storage"][0].credentials.cos_hmac_keys.access_key_id.trim();
secretAccessKey = VCAP["cloud-object-storage"][0].credentials.cos_hmac_keys.secret_access_key.trim();
} catch (error) {
console.error(error);
}
Expand Down
5 changes: 5 additions & 0 deletions web-app/src/components/OurMissionSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ const StyledHands = styled.img`
width: 50%;
min-width: 400px;
}
@media (max-width: ${devices.mobile}) {
width: 100%;
min-width: 0px;
}
`;

export default OurMission;
5 changes: 5 additions & 0 deletions web-app/src/components/WhatHappenedSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ const StyledTree = styled.img`
width: 50%;
min-width: 400px;
}
@media (max-width: ${devices.mobile}) {
width: 100%;
min-width: 0px;
}
`;

export default WhatHappened;
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ exports[`the OurMission component should match the snapshot 1`] = `
}
}
@media (max-width:576px) {
.c5 {
width: 100%;
min-width: 0px;
}
}
<div>
<div
class="c0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ exports[`the WhatHappened component should match the snapshot 1`] = `
}
}
@media (max-width:576px) {
.c3 {
width: 100%;
min-width: 0px;
}
}
<div>
<div
class="c0"
Expand Down
5 changes: 2 additions & 3 deletions web-app/src/pages/homePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ const StyledPage = styled.div`
display: flex;
justify-content: center;
@media (max-width: ${devices.mobile}) {
flex-direction: column;c
flex-direction: column;
}
`;

const PageContainer = styled.div`
`;
const PageContainer = styled.div``;

const HelpSectionWrapper = styled.div`
background-color: ${colours.lightGrey};
Expand Down

0 comments on commit 0e9e3be

Please sign in to comment.