-
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.
- Loading branch information
1 parent
32e45af
commit 27e9275
Showing
14 changed files
with
168 additions
and
95 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { intranetUrls, allowedTargetAgencies } from "../constants.js"; | ||
|
||
/** | ||
* A helper function to get the folder for the agency. | ||
* | ||
* The folder is prefixed with the environment if it is not production. | ||
* Then, it is followed by the agency. | ||
* | ||
* @param {string} env | ||
* @param {string} agency | ||
* @returns {string} the folder name | ||
*/ | ||
|
||
export const getAgencyPath = (env, agency) => { | ||
if (!Object.keys(intranetUrls).includes(env)) { | ||
throw new Error(`Invalid environment: ${env}`); | ||
} | ||
|
||
if (!allowedTargetAgencies.includes(agency)) { | ||
throw new Error(`Invalid agency: ${agency}`); | ||
} | ||
|
||
return env === "production" ? `${agency}` : `${env}-${agency}`; | ||
}; | ||
|
||
/** | ||
* A helper function to get the directory for the snapshot. | ||
* | ||
* @param {Object} props | ||
* @param {string} props.env | ||
* @param {string} props.agency | ||
* @returns {{s3: string, fs: string}} the s3 and fs paths | ||
*/ | ||
|
||
export const getSnapshotPaths = ({ env, agency }) => { | ||
// Get date in format: 2023-01-17 | ||
const dateString = new Date().toISOString().slice(0, 10); | ||
|
||
const s3Path = `${getAgencyPath(env, agency)}/${dateString}`; | ||
|
||
const fsPath = `/tmp/snapshots/${s3Path}`; | ||
|
||
// Return directory for the snapshot | ||
return { s3: s3Path, fs: fsPath }; | ||
}; |
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,78 @@ | ||
import { it } from "@jest/globals"; | ||
|
||
import { getAgencyPath, getSnapshotPaths } from "./paths.js"; | ||
|
||
describe("getAgencyPath", () => { | ||
it("should return the folder name - production", () => { | ||
const env = "production"; | ||
const agency = "hq"; | ||
|
||
const folder = getAgencyPath(env, agency); | ||
|
||
expect(folder).toBe("hq"); | ||
}); | ||
|
||
it("should return the folder name - non-production", () => { | ||
const env = "dev"; | ||
const agency = "hq"; | ||
|
||
const folder = getAgencyPath(env, agency); | ||
|
||
expect(folder).toBe("dev-hq"); | ||
}); | ||
|
||
it("should throw an error - invalid env", () => { | ||
const env = "invalid"; | ||
const agency = "hq"; | ||
|
||
expect(() => getAgencyPath(env, agency)).toThrowError( | ||
`Invalid environment: ${env}`, | ||
); | ||
}); | ||
|
||
it("should throw an error - invalid agency", () => { | ||
const env = "production"; | ||
const agency = "invalid"; | ||
|
||
expect(() => getAgencyPath(env, agency)).toThrowError( | ||
`Invalid agency: ${agency}`, | ||
); | ||
}); | ||
}); | ||
|
||
describe("getSnapshotPaths", () => { | ||
it("should return the s3 and fs paths - production", () => { | ||
const env = "production"; | ||
const agency = "hq"; | ||
|
||
const paths = getSnapshotPaths({ env, agency }); | ||
|
||
expect(paths).toStrictEqual({ | ||
s3: `${agency}/${new Date().toISOString().slice(0, 10)}`, | ||
fs: `/tmp/snapshots/${agency}/${new Date().toISOString().slice(0, 10)}`, | ||
}); | ||
}); | ||
|
||
it("should return the s3 and fs paths - non-production", () => { | ||
const env = "dev"; | ||
const agency = "hq"; | ||
|
||
const paths = getSnapshotPaths({ env, agency }); | ||
|
||
expect(paths).toStrictEqual({ | ||
s3: `dev-${agency}/${new Date().toISOString().slice(0, 10)}`, | ||
fs: `/tmp/snapshots/dev-${agency}/${new Date() | ||
.toISOString() | ||
.slice(0, 10)}`, | ||
}); | ||
}); | ||
|
||
it("should return the s3 and fs paths - invalid env", () => { | ||
const env = "invalid"; | ||
const agency = "hq"; | ||
|
||
expect(() => getSnapshotPaths({ env, agency })).toThrowError( | ||
`Invalid environment: ${env}`, | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.