-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcopy.spec.js
More file actions
83 lines (71 loc) · 2.92 KB
/
copy.spec.js
File metadata and controls
83 lines (71 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import assert from 'node:assert';
const workerUrl = process.env.WORKER_URL;
const ORG = 'da-e2e-test';
describe('/copy operation', function() {
this.timeout(0);
it('copies a file', async () => {
const blob = new Blob(['Hello World!'], { type: "text/html" });
let body = new FormData();
body.append('data', blob);
let opts = {
body,
method: 'POST'
};
let req = new Request(`${workerUrl}/source/${ORG}/copy-spec/test-file.html`, opts);
let resp = await fetch(req);
assert(resp.status === 200 || resp.status === 201);
body = new FormData();
body.append('destination', `${ORG}/copy-spec/test-file-copy.html`)
opts = {
body,
method: 'POST'
}
req = new Request(`${workerUrl}/copy/${ORG}/copy-spec/test-file.html`, opts);
resp = await fetch(req);
assert.strictEqual(resp.status, 204);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-file.html`);
assert.strictEqual(resp.status, 200);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-file-copy.html`);
assert.strictEqual(resp.status, 200);
const content = await resp.text();
assert.strictEqual(content, 'Hello World!');
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-file.html`, { method: 'DELETE' });
assert.strictEqual(resp.status, 204);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-file-copy.html`, { method: 'DELETE' });
assert.strictEqual(resp.status, 204);
});
it('copies a folder', async () => {
const limit = 5;
for (let i = 0; i < limit; i++) {
const blob = new Blob(['Hello World!'], { type: "text/html" });
let body = new FormData();
body.append('data', blob);
let opts = {
body,
method: 'POST'
};
let req = new Request(`${workerUrl}/source/${ORG}/copy-spec/test-folder/index${i}.html`, opts);
let resp = await fetch(req);
assert(resp.status === 200 || resp.status === 201);
}
const body = new FormData();
body.append('destination', `/${ORG}/copy-spec/test-folder-copy`);
const opts = {
body,
method: 'POST',
};
const req = new Request(`${workerUrl}/copy/${ORG}/copy-spec/test-folder`, opts);
const resp = await fetch(req);
assert.strictEqual(resp.status, 204);
for (let i = 0; i < limit; i++) {
let resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-folder/index${i}.html`);
assert.strictEqual(resp.status, 200);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-folder-copy/index${i}.html`);
assert.strictEqual(resp.status, 200);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-folder/index${i}.html`, { method: 'DELETE' });
assert.strictEqual(resp.status, 204);
resp = await fetch(`${workerUrl}/source/${ORG}/copy-spec/test-folder-copy/index${i}.html`, { method: 'DELETE' });
assert.strictEqual(resp.status, 204);
}
});
});