chore: Move upload tests to HTTP layer (#7610)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import FormData from "form-data"
|
||||
import fs from "fs/promises"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
} from "../../../helpers/create-admin-user"
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -27,24 +28,16 @@ const getUploadReq = (files: { name: string; content: string }[]) => {
|
||||
}
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env: {
|
||||
MEDUSA_FF_MEDUSA_V2: true,
|
||||
},
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
let appContainer
|
||||
beforeAll(() => {})
|
||||
afterAll(async () => {
|
||||
await fs.rm(path.join(process.cwd(), "uploads"), { recursive: true })
|
||||
await fs.rm(path.join(os.tmpdir(), "uploads"), { recursive: true })
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
appContainer = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||
})
|
||||
|
||||
describe("POST /admin/uploads", () => {
|
||||
beforeEach(async () => {})
|
||||
|
||||
it("uploads a single file successfully", async () => {
|
||||
const { form, meta } = getUploadReq([
|
||||
{ name: "first.jpeg", content: "first content" },
|
||||
@@ -1,4 +1,7 @@
|
||||
const { defineConfig, Modules } = require("@medusajs/utils")
|
||||
const os = require("os")
|
||||
const path = require("path")
|
||||
|
||||
const DB_HOST = process.env.DB_HOST
|
||||
const DB_USERNAME = process.env.DB_USERNAME
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
@@ -32,5 +35,21 @@ module.exports = defineConfig({
|
||||
providers: [customFulfillmentProvider],
|
||||
},
|
||||
},
|
||||
[Modules.FILE]: {
|
||||
resolve: "@medusajs/file",
|
||||
options: {
|
||||
providers: [
|
||||
{
|
||||
resolve: "@medusajs/file-local-next",
|
||||
options: {
|
||||
config: {
|
||||
// This is the directory where we can reliably write in CI environments
|
||||
local: { upload_dir: path.join(os.tmpdir(), "uploads") },
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@ export class LocalFileService extends AbstractFileProviderService {
|
||||
|
||||
constructor(_, options: LocalFileServiceOptions) {
|
||||
super()
|
||||
this.uploadDir_ = options?.upload_dir || "uploads"
|
||||
this.uploadDir_ = options?.upload_dir || path.join(__dirname, "uploads")
|
||||
this.backendUrl_ = options?.backend_url || "http://localhost:9000"
|
||||
}
|
||||
|
||||
@@ -29,10 +29,7 @@ export class LocalFileService extends AbstractFileProviderService {
|
||||
}
|
||||
|
||||
const parsedFilename = path.parse(file.filename)
|
||||
|
||||
if (parsedFilename.dir) {
|
||||
this.ensureDirExists(parsedFilename.dir)
|
||||
}
|
||||
await this.ensureDirExists(parsedFilename.dir)
|
||||
|
||||
const fileKey = path.join(
|
||||
parsedFilename.dir,
|
||||
|
||||
Reference in New Issue
Block a user