修改未完成
This commit is contained in:
@@ -43,30 +43,11 @@ const run = async () => {
|
||||
},
|
||||
};
|
||||
const uploads = [];
|
||||
const singleUploads = [];
|
||||
globalThis.plus = {
|
||||
uploader: {
|
||||
createUpload(url, options, callback) {
|
||||
const upload = {
|
||||
headers: {},
|
||||
files: [],
|
||||
setRequestHeader(key, value) { this.headers[key] = value; },
|
||||
addFile(filePath, fileOptions) { this.files.push({ filePath, fileOptions }); },
|
||||
start() { queueMicrotask(() => callback({ responseText: JSON.stringify({ code: 200, data: null }) }, 200)); },
|
||||
abort() {},
|
||||
};
|
||||
uploads.push({ url, options, upload });
|
||||
return upload;
|
||||
},
|
||||
},
|
||||
};
|
||||
globalThis.uni.uploadFile = (options) => {
|
||||
singleUploads.push(options);
|
||||
queueMicrotask(() => options.success({
|
||||
statusCode: 200,
|
||||
data: JSON.stringify({ code: 200, data: { ossId: "900002", url: "https://oss.example/single.png", thumbnailUrl: "", fileName: "single.png" } }),
|
||||
}));
|
||||
return { abort() {} };
|
||||
const task = { abort() {} };
|
||||
uploads.push({ options, task });
|
||||
queueMicrotask(() => options.success({ statusCode: 200, data: JSON.stringify({ code: 200, data: null }) }));
|
||||
return task;
|
||||
};
|
||||
const { appApi } = await import(toDataModuleUrl(`${prelude}\n${moduleBody}`));
|
||||
const basePayload = {
|
||||
@@ -110,9 +91,46 @@ const run = async () => {
|
||||
filePath: "/storage/emulated/0/avatar.png",
|
||||
});
|
||||
assert.strictEqual(uploads.length, 1);
|
||||
assert.strictEqual(uploads[0].url, "https://backend-api.ddxcjp.cn/genealogy/app/files/resumable/chunk?uploadId=upload-1&chunkIndex=0&chunkMd5=" + "b".repeat(32));
|
||||
assert.deepStrictEqual(uploads[0].upload.headers, { clientid: "client-1", tenantId: "000000", Authorization: "Bearer session-1" });
|
||||
assert.deepStrictEqual(uploads[0].upload.files, [{ filePath: "/storage/emulated/0/avatar.png", fileOptions: { key: "file" } }]);
|
||||
assert.strictEqual(uploads[0].options.url, "https://backend-api.ddxcjp.cn/genealogy/app/files/resumable/chunk");
|
||||
assert.strictEqual(uploads[0].options.filePath, "/storage/emulated/0/avatar.png");
|
||||
assert.strictEqual(uploads[0].options.name, "file");
|
||||
assert.strictEqual(uploads[0].options.timeout, 15000);
|
||||
assert.deepStrictEqual(uploads[0].options.header, { clientid: "client-1", tenantId: "000000", Authorization: "Bearer session-1" });
|
||||
assert.deepStrictEqual(uploads[0].options.formData, { uploadId: "upload-1", chunkIndex: "0", chunkMd5: "b".repeat(32) });
|
||||
|
||||
globalThis.uni.uploadFile = (options) => {
|
||||
queueMicrotask(() => options.fail({ errMsg: "uploadFile:fail timeout" }));
|
||||
return { abort() {} };
|
||||
};
|
||||
await assert.rejects(appApi.uploadResumableChunk({
|
||||
uploadId: "upload-1",
|
||||
chunkIndex: 0,
|
||||
chunkMd5: "b".repeat(32),
|
||||
filePath: "/storage/emulated/0/avatar.png",
|
||||
}), (error) => error.code === "REQUEST_TIMEOUT");
|
||||
|
||||
const browserRequests = [];
|
||||
class TestFormData {
|
||||
entries = [];
|
||||
append(name, value, fileName) { this.entries.push({ name, value, fileName }); }
|
||||
}
|
||||
globalThis.FormData = TestFormData;
|
||||
globalThis.fetch = async (url, options) => {
|
||||
browserRequests.push({ url, options });
|
||||
return { status: 200, text: async () => JSON.stringify({ code: 200, data: null }) };
|
||||
};
|
||||
await appApi.uploadBrowserResumableChunk({
|
||||
uploadId: "upload-1",
|
||||
chunkIndex: 0,
|
||||
chunkMd5: "b".repeat(32),
|
||||
}, { name: "avatar.png" });
|
||||
assert.strictEqual(browserRequests[0].url, "https://backend-api.ddxcjp.cn/genealogy/app/files/resumable/chunk");
|
||||
assert.deepStrictEqual(browserRequests[0].options.body.entries, [
|
||||
{ name: "uploadId", value: "upload-1", fileName: undefined },
|
||||
{ name: "chunkIndex", value: "0", fileName: undefined },
|
||||
{ name: "chunkMd5", value: "b".repeat(32), fileName: undefined },
|
||||
{ name: "file", value: { name: "avatar.png" }, fileName: "avatar.png" },
|
||||
]);
|
||||
|
||||
response = { statusCode: 200, data: { code: 200, data: { ossId: "900001", url: "https://oss.example/avatar.png", thumbnailUrl: "", fileName: "avatar.png" } } };
|
||||
assert.deepStrictEqual(await appApi.completeResumableUpload(completePayload), {
|
||||
@@ -122,39 +140,6 @@ const run = async () => {
|
||||
fileName: "avatar.png",
|
||||
});
|
||||
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/files/resumable/complete");
|
||||
assert.deepStrictEqual(await appApi.uploadSingleFile({ filePath: "/storage/emulated/0/single.png" }), {
|
||||
ossId: "900002",
|
||||
url: "https://oss.example/single.png",
|
||||
thumbnailUrl: "",
|
||||
fileName: "single.png",
|
||||
});
|
||||
assert.strictEqual(singleUploads.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/files/upload");
|
||||
assert.strictEqual(singleUploads.at(-1).name, "file");
|
||||
assert.strictEqual(singleUploads.at(-1).filePath, "/storage/emulated/0/single.png");
|
||||
assert.deepStrictEqual(singleUploads.at(-1).header, { clientid: "client-1", tenantId: "000000", Authorization: "Bearer session-1" });
|
||||
|
||||
response = { statusCode: 200, data: { code: 200, data: null } };
|
||||
await appApi.createFileReference({
|
||||
bizType: "family_feed",
|
||||
bizName: "family feed image",
|
||||
bizTable: "gen_family_feed",
|
||||
bizId: "900013001",
|
||||
bizField: "media_oss_ids",
|
||||
ossId: "900002",
|
||||
usageScene: "feed_image",
|
||||
});
|
||||
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/files/reference");
|
||||
assert.deepStrictEqual(requests.at(-1).data, {
|
||||
bizType: "family_feed",
|
||||
bizName: "family feed image",
|
||||
bizTable: "gen_family_feed",
|
||||
bizId: 900013001,
|
||||
bizField: "media_oss_ids",
|
||||
ossId: 900002,
|
||||
usageScene: "feed_image",
|
||||
});
|
||||
await appApi.deleteFileReference({ bizTable: "gen_family_feed", bizId: "900013001", bizField: "media_oss_ids" });
|
||||
assert.strictEqual(requests.at(-1).url, "https://backend-api.ddxcjp.cn/genealogy/app/files/reference?bizTable=gen_family_feed&bizId=900013001&bizField=media_oss_ids");
|
||||
await assert.rejects(
|
||||
appApi.initializeResumableUpload({ ...basePayload, totalSize: 0 }),
|
||||
/totalSize/,
|
||||
@@ -164,8 +149,9 @@ const run = async () => {
|
||||
/chunkIndex/,
|
||||
);
|
||||
|
||||
delete globalThis.plus;
|
||||
delete globalThis.uni;
|
||||
delete globalThis.fetch;
|
||||
delete globalThis.FormData;
|
||||
process.stdout.write("FILE-UPLOAD-API-RUNTIME-SMOKE PASS\n");
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user