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

Remove app-deployment file #344

Merged
merged 5 commits into from
Jan 22, 2025
Merged

Remove app-deployment file #344

merged 5 commits into from
Jan 22, 2025

Conversation

flurdy
Copy link
Contributor

@flurdy flurdy commented Jan 17, 2025

Calls new remove service from cdp-app-deployments

*/
export async function deleteDeploymentFiles({
serviceName,
logger = createLogger()
Copy link
Contributor

@feedmypixel feedmypixel Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is being passed in for ease of testing? Why not just mock the logger in tests? Then you don't have "test code" in production code. Which I'm not a massive fan of

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't pass the logger the statements from different async calls tend to be out of sync and harder to trace the journey. Also this seems a lot tidier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Thats a bit of a smell and I'd say there is something else going on there if async logs are not showing in order and you have to pass the logger around to make them. Might need some more investigation as to the cause of this issue?

import { deleteDeploymentFiles } from '~/src/api/undeploy/helpers/delete-deployment-file.js'

jest.mock('~/src/helpers/feature-toggle/is-feature-enabled')
jest.mock('~/src/helpers/remove/workflows/remove-deployment')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a lot of mocking going on here. Looks like this is just testing inputs and outputs. Lots of mocks in tests for me is a smell. The code can change, the tests stay mocked and green. Real code being tested is being missed. Can the mocks be removed? Or go down to a lower level? Can the http calls be mocked with nock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a simple function and it's just testing if the feature toggle is respected. That is the only branching.

Overriding process.env.??? was not really working and looked messy and I don't really want to be testing how config works in this unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now granted there are other functions that mock too much but not this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding process.env.??? was not really working and looked messy and I don't really want to be testing how config works in this unit test.

You can mock out config quite nicely in tests. If needed. Theres examples around https://github.com/DEFRA/cdp-user-service-backend/blob/6c57e6e7b9460f0d55c27fe383ae9877674aae4d/src/helpers/proxy.test.js#L17-L25

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link. I will try and use that in the future. Did not think of config.set as an option

}

await removeAppConfig(serviceName, logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise.all() or Promise.allSettled() would mean these can become parallel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do, but there is no need as this has no performance or concurrency requirements. In fact, as sequential as possible is preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️ isn't always better 😅

await removeTenantInfrastructure(serviceName, logger)
} else {
logger.info('Remove service workflows feature is disabled')
await removeDashboard(serviceName, logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise.all() or Promise.allSettled() would mean these can become parallel

@flurdy flurdy merged commit c2db2fd into main Jan 22, 2025
1 check passed
@flurdy flurdy deleted the 485020-app-depl branch January 22, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants