chore(tests): Try to use the api integration tests for v2 (#6588)

Few things to keep in mind:
1. You need to set MEDUSA_FF_MEDUSA_V2 to true before running the tests to run with the v2 API
2. You can use the `breaking` function to differentiate between v1 and v2 differences. This can help us identify what was breaking pretty quickly afterwards
3. You will need to run specific tests for now instead of all if you want to target v2. I think that's fine though, as we don't really need these to run on every PR until we have feature parity (and by then, all tests would be both v1 and v2 compatible)


**note: Adrien** 
- add a new way to load modules only to run their loaders comparable to the way to run the migrations only
- improve tests runner to cleanup the data properly as well as re running all loaders and core defaults

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
Stevche RadevskiandAdrien de Peretti authored and GitHub committed 2024-03-07 08:05:43 +00:00
1 parent 000eb61e33
commit 12b035cb18
76 files changed
+773 -371

No files matched your search

@@ -4,10 +4,13 @@ export const defaultAdminStoreFields = [
"id",
"name",
"supported_currency_codes",
"default_currency_code",
"default_sales_channel_id",
"default_region_id",
"default_location_id",
"metadata",
"created_at",
"updated_at",
]
export const retrieveTransformQueryConfig = {
@@ -1,9 +1,12 @@
import { remoteQueryObjectFromString } from "@medusajs/utils"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
import { defaultAdminStoreFields } from "./query-config"
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const queryObject = remoteQueryObjectFromString({
entryPoint: "store",
@@ -51,6 +51,10 @@ export class AdminPostStoresStoreReq {
@IsArray()
supported_currency_codes?: string[]
@IsOptional()
@IsString()
default_currency_code?: string
@IsOptional()
@IsString()
default_sales_channel_id?: string
+68
View File
@@ -231,4 +231,72 @@ export const loadMedusaApp = async (
return medusaApp
}
/**
* Run the modules loader without taking care of anything else. This is useful for running the loader as a separate action or to re run all modules loaders.
*
* @param configModule
* @param container
*/
export async function runModulesLoader({
configModule,
container,
}: {
configModule: {
modules?: CommonTypes.ConfigModule["modules"]
projectConfig: CommonTypes.ConfigModule["projectConfig"]
}
container: MedusaContainer
}): Promise<void> {
const featureFlagRouter = container.resolve<FlagRouter>("featureFlagRouter")
const injectedDependencies = {
[ContainerRegistrationKeys.PG_CONNECTION]: container.resolve(
ContainerRegistrationKeys.PG_CONNECTION
),
[ContainerRegistrationKeys.LOGGER]: container.resolve(
ContainerRegistrationKeys.LOGGER
),
}
const sharedResourcesConfig = {
database: {
clientUrl: configModule.projectConfig.database_url,
driverOptions: configModule.projectConfig.database_extra,
debug: !!(configModule.projectConfig.database_logging ?? false),
},
}
const configModules = mergeDefaultModules(configModule.modules)
// Apply default options to legacy modules
for (const moduleKey of Object.keys(configModules)) {
if (!ModulesDefinition[moduleKey]?.isLegacy) {
continue
}
if (isObject(configModules[moduleKey])) {
;(
configModules[moduleKey] as Partial<InternalModuleDeclaration>
).options ??= {
database: {
type: "postgres",
url: configModule.projectConfig.database_url,
extra: configModule.projectConfig.database_extra,
schema: configModule.projectConfig.database_schema,
logging: configModule.projectConfig.database_logging,
},
}
}
}
await MedusaApp({
modulesConfig: configModules,
servicesConfig: joinerConfig,
remoteFetchData: remoteQueryFetchData(container),
sharedContainer: container,
sharedResourcesConfig,
injectedDependencies,
loaderOnly: true,
})
}
export default loadMedusaApp