Skip to content

refactor: improve test isolation for Axios API logic #13125

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

Merged
merged 9 commits into from
May 12, 2024
Prev Previous commit
Next Next commit
fix: remove temp comments
  • Loading branch information
Parkreiner committed May 7, 2024
commit 654df181eefc251e629c397527900d624755433c
8 changes: 0 additions & 8 deletions site/src/api/api.ts
Copy link
Member Author

@Parkreiner Parkreiner May 7, 2024

Choose a reason for hiding this comment

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

To give a high-level overview of the file now, there's basically four categories of things in here now:

  • Api class – Defines all the Axios-based API calls in one spot
  • Client class – Top-level wrapper for client-ish functionality; contains an Api instance
  • Ad-hoc helper functions – these weren't moved into either class because, while they help with the API calls, they don't actually have any reliance on Axios. These are all stateless functions
  • Additional types – I wish I could move these closer to the methods where they're used, but that's one of the tradeoffs with classes – you can't put type definitions between methods

I was very deliberate about not changing any of the functionality for the methods/functions, aside from changing variable references. You can assume all the overall functionality should be unchanged (especially if the unit/E2E tests are still passing)

Honestly, though, with how many changes this file has, it might be worth looking at it without the diffs

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import userAgentParser from "ua-parser-js";
import { delay } from "../utils/delay";
import * as TypesGen from "./typesGenerated";

////////////////////////////////////////////////////////////////////////////////
// START OF API FILE
////////////////////////////////////////////////////////////////////////////////

const getMissingParameters = (
oldBuildParameters: TypesGen.WorkspaceBuildParameter[],
newBuildParameters: TypesGen.WorkspaceBuildParameter[],
Expand Down Expand Up @@ -1847,10 +1843,6 @@ export class Api {
};
}

////////////////////////////////////////////////////////////////////////////////
// START OF CLIENT FILE
////////////////////////////////////////////////////////////////////////////////

// This is a hard coded CSRF token/cookie pair for local development. In prod,
// the GoLang webserver generates a random cookie with a new token for each
// document request. For local development, we don't use the Go webserver for
Expand Down
Loading