**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { resolve } from "path"
|
|
import { Modules } from "@medusajs/utils"
|
|
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
|
import { Entity, PrimaryKey } from "@mikro-orm/core"
|
|
import { IFileModuleService } from "@medusajs/types"
|
|
|
|
jest.setTimeout(100000)
|
|
|
|
// The test runner throws if a model is not passed, so we create a dummy entity
|
|
@Entity({ tableName: "dummy_file_entity" })
|
|
export default class DummyEntity {
|
|
@PrimaryKey()
|
|
id: string
|
|
}
|
|
|
|
const moduleOptions = {
|
|
providers: [
|
|
{
|
|
resolve: resolve(
|
|
process.cwd() +
|
|
"/integration-tests/__fixtures__/providers/default-provider"
|
|
),
|
|
options: {
|
|
config: {
|
|
"default-provider": {},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
}
|
|
|
|
moduleIntegrationTestRunner<IFileModuleService>({
|
|
moduleName: Modules.FILE,
|
|
moduleOptions: moduleOptions,
|
|
moduleModels: [DummyEntity],
|
|
testSuite: ({ service }) => {
|
|
describe("File Module Service", () => {
|
|
it("creates and gets a file", async () => {
|
|
const res = await service.createFiles({
|
|
filename: "test.jpg",
|
|
mimeType: "image/jpeg",
|
|
content: Buffer.from("test"),
|
|
})
|
|
|
|
expect(res).toEqual({
|
|
id: "test.jpg",
|
|
url: "test.jpg",
|
|
})
|
|
|
|
// The fake provider returns the file content as the url
|
|
const downloadUrl = await service.retrieveFile("test.jpg")
|
|
expect(await new Response(downloadUrl.url).text()).toEqual("test")
|
|
})
|
|
})
|
|
},
|
|
})
|