Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move E2E env var logic to docker-compose #1915

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE=https://buckinghamshire.${BOPS_API_ROOT_DOMA
#
## End-to-end test team (borrows Lambeth's details)
GOV_UK_PAY_TOKEN_E2E=👻
UNIFORM_CLIENT_E2E=e2e:123
BOPS_SUBMISSION_URL_E2E=https://lambeth.${BOPS_API_ROOT_DOMAIN}
35 changes: 6 additions & 29 deletions api.planx.uk/send/uniform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,13 @@ async function authenticate({
clientId,
clientSecret,
}: UniformClient): Promise<UniformAuthResponse> {
const isTest = clientId.toUpperCase() === "E2E";

const target = isTest
? process.env.E2E_MOCK_SERVER!
: process.env.UNIFORM_TOKEN_URL!;

const authString = Buffer.from(`${clientId}:${clientSecret}`).toString(
"base64"
);

const authConfig: AxiosRequestConfig = {
method: "POST",
url: target,
url: process.env.UNIFORM_TOKEN_URL!,
headers: {
Authorization: `Basic ${authString}`,
"Content-type": "application/x-www-form-urlencoded",
Expand All @@ -305,7 +299,7 @@ async function authenticate({
}

const uniformAuthResponse: UniformAuthResponse = {
token: isTest ? "TEST_TOKEN" : response.data.access_token,
token: response.data.access_token,
organisation: response.data["organisation-name"],
organisationId: response.data["organisation-id"],
};
Expand All @@ -323,15 +317,9 @@ async function createSubmission(
organisationId: string,
sessionId = "TEST"
): Promise<string> {
const isTest = token === "TEST_TOKEN";

const submissionURL = isTest
? process.env.E2E_MOCK_SERVER!
: process.env.UNIFORM_SUBMISSION_URL!;

const createSubmissionEndpoint = `${submissionURL}/secure/submission`;
const createSubmissionEndpoint = `${process.env.UNIFORM_SUBMISSION_URL!}/secure/submission`;

const isStaging = isTest || submissionURL.includes("staging");
const isStaging = ["mock-server", "staging"].some(hostname => createSubmissionEndpoint.includes(hostname));

const createSubmissionConfig: AxiosRequestConfig = {
url: createSubmissionEndpoint,
Expand Down Expand Up @@ -380,13 +368,8 @@ async function attachArchive(
);
return false;
}
const isTest = token === "TEST_TOKEN";

const submissionURL = isTest
? process.env.E2E_MOCK_SERVER!
: process.env.UNIFORM_SUBMISSION_URL!;

const attachArchiveEndpoint = `${submissionURL}/secure/submission/${submissionId}/archive`;
const attachArchiveEndpoint = `${process.env.UNIFORM_SUBMISSION_URL!}/secure/submission/${submissionId}/archive`;

const formData = new FormData();
formData.append("file", fs.createReadStream(zipPath));
Expand Down Expand Up @@ -417,13 +400,7 @@ async function retrieveSubmission(
token: string,
submissionId: string
): Promise<UniformSubmissionResponse> {
const isTest = token === "TEST_TOKEN";

const submissionURL = isTest
? process.env.E2E_MOCK_SERVER!
: process.env.UNIFORM_SUBMISSION_URL!;

const getSubmissionEndpoint = `${submissionURL}/secure/submission/${submissionId}`;
const getSubmissionEndpoint = `${process.env.UNIFORM_SUBMISSION_URL!}/secure/submission/${submissionId}`;

const getSubmissionConfig: AxiosRequestConfig = {
url: getSubmissionEndpoint,
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ services:
condition: service_healthy
entrypoint: sh
command: -c "echo ready for testing"

api:
environment:
UNIFORM_SUBMISSION_URL: http://mock-server:8080
UNIFORM_TOKEN_URL: http://mock-server:8080
UNIFORM_CLIENT_E2E: e2e:123
GOV_UK_PAY_TOKEN_E2E: ${GOV_UK_PAY_TOKEN_E2E}
BOPS_SUBMISSION_URL_E2E: http://mock-server:8080
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ services:
UNIFORM_CLIENT_CHILTERN: ${UNIFORM_CLIENT_CHILTERN}
UNIFORM_CLIENT_WYCOMBE: ${UNIFORM_CLIENT_WYCOMBE}
BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE: ${BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE}
# E2E
GOV_UK_PAY_TOKEN_E2E: ${GOV_UK_PAY_TOKEN_E2E}
E2E_MOCK_SERVER: http://mock-server:8080
UNIFORM_CLIENT_E2E: ${UNIFORM_CLIENT_E2E}
BOPS_SUBMISSION_URL_E2E: http://mock-server:8080

sharedb:
restart: unless-stopped
Expand Down
Loading