stencil
stencil copied to clipboard
[stencil] tests for file upload interceptor
Description
There is a file-upload interceptor in the common
package which helps enable the file upload functionality in a stencil app by just registering the interceptor wherever required. The task is to add tests for this interceptor.
Goals
- [ ] test for the
file-upload
interceptor
Implementational Details
Create a test file named file-upload.interceptor.spec.ts
in the tests directory and write the required test cases using jest
. Make sure to cover all edge cases.
Product Name
Stencil
Organisation Name
SamagraX
Tech Skills Needed
TypeScript, Jest, SuperTest, Software Testing
Mentors
@techsavvyash
Complexity
Medium
Category
Software Testing
Test Case List
Some of the test cases I would want you to add tests for are:
Saving to local storage
- filename is simple:
test.txt
- file name has multiple periods:
text.tar.gz
- the service should throw for illegal filenames like:
foo/bar.xz
or../foo.txt
orfoo/../bar.ext
- filename without extensions are allowed
filename
- It is throwing if the
STORAGE_ENDPOINT
directory does not exist - It is throwing if the
destination
directory does not exist. - Allowing for files with spaces in the same
foo bar.ext
- Allows for empty
destination
parameter and stores in the root ofSTORAGE_ENDPOINT
folder.
Uploading to minIO
Uploads over HTTP (process.env.STORAGE_USE_SSL
=== false)
- The returned urls have
http
and port number mentioned - All the cases from
# Saving to local storage
while treatingSTORAGE_ENDPOINT
as the minio endpoint anddestination
as the bucket name.
Uploads pver HTTPS (process.env.STORAGE_USE_SSL
=== true)
- Returned urls have
https
always but only contain port numbers in case of directIPv4
orIPv6
addresses in theSTORAGE_ENDPOINT
. (For example returned url should look like:https://<IP>:<PORT>/destination/filename
) - Returned urls have
https
but not the port number in case theSTORAGE_ENDPOINT
is a proper url such ascdn-api.dev.samagra.io
. (For example returned url should look like:https://cdn-api.dev.samagra.io/destination/filename
) - All the cases from
# Saving to local storage
while treatingSTORAGE_ENDPOINT
as the minio endpoint anddestination
as the bucket name.
Make-Bucket Endpoint
- Test the
make-bucket
endpoint forlocal storage
- Test the
make-bucket
endpoint forminio
Downloads
- make sure illegal
destination
parameters like../foo/bar
are rejected right of the back. - Make sure test case 1 for
filenames
as well. - Make sure we are able to retrieve the file we uploaded correctly when passing legal params.
Ad-Hoc
- Include test cases for util functions if you feel like some particular case can be tested out and i have misse