Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Updated the tests with extended Act class and assertions with single step checks

See: #13604
  • Loading branch information
radoslawkrzemien committed Jun 30, 2023
1 parent 951fae7 commit 9f793d9
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 167 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/preDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Process new code merged to main

on:
push:
branches: [main]
branches:
- main

jobs:
lint:
Expand Down
41 changes: 25 additions & 16 deletions workflow_tests/assertions/deployAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ const assertValidateJobExecuted = (workflowResult, didExecute = true) => {
output: '',
},
];
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand All @@ -34,11 +37,11 @@ const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => {
[{key: 'ref', value: 'staging'}, {key: 'token', value: '***'}],
),
utils.getStepAssertion(
'Setup git for ***',
'Setup git for OSBotify',
true,
null,
'DEPLOY_STAGING',
'Setting up git for ***',
'Setting up git for OSBotify',
[{key: 'GPG_PASSPHRASE', value: '***'}],
),
utils.getStepAssertion(
Expand All @@ -56,10 +59,13 @@ const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => {
'Pushing tag to trigger staging deploy',
),
];
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand All @@ -74,11 +80,11 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
[{key: 'fetch-depth', value: '0'}, {key: 'token', value: '***'}],
),
utils.getStepAssertion(
'Setup git for ***',
'Setup git for OSBotify',
true,
null,
'DEPLOY_PRODUCTION',
'Setting up git for ***',
'Setting up git for OSBotify',
[{key: 'GPG_PASSPHRASE', value: '***'}],
),
utils.getStepAssertion(
Expand Down Expand Up @@ -121,10 +127,13 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
[{key: 'GITHUB_TOKEN', value: '***'}],
),
];
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down
105 changes: 65 additions & 40 deletions workflow_tests/assertions/platformDeployAssertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ const assertVerifyActorJobExecuted = (workflowResult, didExecute = true) => {
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'team', value: 'mobile-deployers'}],
),
];
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -117,10 +120,13 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio
),
);
}
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}

const failProdSteps = [
Expand All @@ -134,10 +140,13 @@ const assertAndroidJobExecuted = (workflowResult, didExecute = true, isProductio
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'SLACK_WEBHOOK_URL', value: '***'}],
),
];
if (didExecute && isProduction && !isSuccessful) {
expect(workflowResult).toEqual(expect.arrayContaining(failProdSteps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(failProdSteps));

for (const expectedStep of failProdSteps) {
if (didExecute && isProduction && !isSuccessful) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -194,10 +203,12 @@ const assertDesktopJobExecuted = (workflowResult, didExecute = true, isProductio
);
}

if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));
for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -317,10 +328,13 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction =
),
);
}
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));

for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}

const failProdSteps = [
Expand All @@ -334,10 +348,13 @@ const assertIOSJobExecuted = (workflowResult, didExecute = true, isProduction =
[{key: 'GITHUB_TOKEN', value: '***'}, {key: 'SLACK_WEBHOOK_URL', value: '***'}],
),
];
if (didExecute && isProduction && !isSuccessful) {
expect(workflowResult).toEqual(expect.arrayContaining(failProdSteps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(failProdSteps));

for (const expectedStep of failProdSteps) {
if (didExecute && isProduction && !isSuccessful) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -444,10 +461,12 @@ const assertWebJobExecuted = (workflowResult, didExecute = true, isProduction =
);
}

if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));
for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand All @@ -463,10 +482,12 @@ const assertPostSlackOnFailureJobExecuted = (workflowResult, didExecute = true)
),
];

if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));
for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -519,10 +540,12 @@ const assertPostSlackOnSuccessJobExecuted = (workflowResult, didExecute = true,
);
}

if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));
for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down Expand Up @@ -568,10 +591,12 @@ const assertPostGithubCommentJobExecuted = (workflowResult, didExecute = true, i
),
];

if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining(steps));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining(steps));
for (const expectedStep of steps) {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
}
};

Expand Down
Loading

0 comments on commit 9f793d9

Please sign in to comment.