Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7511294
uploaded-files.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
uploaded-files.test.ts
View Options
import
assert
from
"assert"
;
import
FileField
from
"../../app/base-chips/field-types/file"
;
import
{
Collection
,
File
}
from
"../../main"
;
import
asyncRequest
from
"../../test_utils/async-request"
;
import
{
TestApp
}
from
"../../test_utils/test-app"
;
import
{
withRunningApp
}
from
"../../test_utils/with-test-app"
;
describe
(
"uploaded_files"
,
()
=>
{
it
(
"has a test"
,
()
=>
{
return
withRunningApp
(
(
test_app_type
)
=>
{
return
class
extends
test_app_type
{
collections
=
{
...
TestApp
.
BaseCollections
,
with_file
:
new
(
class
extends
Collection
{
fields
=
{
file
:
new
FileField
(),
};
})(),
};
};
},
async
({
port
,
rest_api
})
=>
{
const
form_data
=
'------------------------------4ebf00fbcf09\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\nContent-Type: text/plain\r\n\r\nI AM A TEST\r\n\r\n\r\n------------------------------4ebf00fbcf09--'
;
const
options
=
{
hostname
:
"localhost"
,
port
:
port
,
path
:
"/api/v1/collections/with_file"
,
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"multipart/form-data; boundary=----------------------------4ebf00fbcf09"
,
},
};
const
{
id
}
=
(
await
asyncRequest
(
options
,
form_data
))
as
Record
<
"file"
|
"id"
,
string
>
;
const
{
items
:
[
data
],
}
=
(
await
asyncRequest
({
method
:
"GET"
,
hostname
:
"localhost"
,
port
:
port
,
path
:
"/api/v1/collections/with_file/"
+
id
+
"?format[file]=url"
,
}))
as
Record
<
string
,
{
file
:
string
}[]
>
;
const
url_regex
=
new
RegExp
(
/\/api\/v1\/uploaded-files\/\S*\/test.txt/
);
assert
.
match
(
data
.
file
,
url_regex
);
const
response
=
await
rest_api
.
get
(
data
.
file
);
assert
.
strictEqual
(
response
,
"I AM A TEST\r\n\r\n"
);
}
);
});
it
(
"properly handles files with non-ascii filenames"
,
()
=>
{
return
withRunningApp
(
(
test_app_type
)
=>
{
return
class
extends
test_app_type
{
collections
=
{
...
TestApp
.
BaseCollections
,
files
:
new
(
class
extends
Collection
{
fields
=
{
file
:
new
FileField
(),
};
})(),
};
};
},
async
({
port
,
rest_api
,
app
})
=>
{
const
file
=
await
File
.
fromData
(
app
,
"ABC"
,
"ąęćż.txt"
);
const
file_item
=
await
app
.
collections
.
files
.
suCreate
({
file
,
});
const
{
items
:
[
file_item_new
],
}
=
await
app
.
collections
.
files
.
suList
()
.
ids
([
file_item
.
id
])
.
format
({
file
:
"file"
})
.
fetch
();
const
url
=
(
file_item_new
.
get
(
"file"
)
as
File
)
?
.
getURL
();
if
(
!
url
)
{
throw
new
Error
(
"Missing url"
);
}
const
response
=
await
rest_api
.
get
(
url
);
}
);
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Jul 21, 00:19 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
803019
Default Alt Text
uploaded-files.test.ts (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment