Repository navigation
Expand file tree
/
Copy pathupload_file.test.js
More file actions
33 lines (27 loc) · 1.51 KB
/
Copy pathupload_file.test.js
File metadata and controls
33 lines (27 loc) · 1.51 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
const assert = require('node:assert/strict');
const { readFileSync } = require('node:fs');
const test = require('node:test');
const uploadFileSource = readFileSync('upload_file.tsx', 'utf8');
const loginSource = readFileSync('Login.tsx', 'utf8');
test('upload_file.tsx consolidates and re-exports shared Login implementation', () => {
assert.match(uploadFileSource, /export\s+\{\s*IncorrectUpload\s*\}\s+from\s+['"]\.\/Login['"]/);
});
test('consolidated source sends the selected file with FormData instead of JSON', () => {
assert.match(loginSource, /new\s+FormData\s*\(/);
assert.match(loginSource, /\.append\(\s*['"]file['"],\s*file,\s*file\.name\s*\)/);
assert.doesNotMatch(loginSource, /JSON\.stringify/);
assert.doesNotMatch(loginSource, /Content-Type['"]?\s*:\s*['"]application\/json/);
});
test('consolidated source stores a single File from the FileList', () => {
assert.match(loginSource, /setFile\(\s*event\.target\.files\??\.\[0\]\s*\?\?\s*null\)/);
});
test('no hardcoded endpoint remains in upload_file.tsx or Login.tsx', () => {
assert.doesNotMatch(uploadFileSource, /https?:\/\//);
assert.doesNotMatch(loginSource, /fetch\(\s*['"]https?:\/\//);
});
test('upload has synchronous ref-based guard against double submit', () => {
assert.match(source, /isUploadingRef\s*=\s*useRef\(\s*false\s*\)/);
assert.match(source, /if\s*\(\s*isUploadingRef\.current\s*\)\s*\{\s*return;?\s*\}/);
assert.match(source, /isUploadingRef\.current\s*=\s*true/);
assert.match(source, /isUploadingRef\.current\s*=\s*false/);
});