stencil icon indicating copy to clipboard operation
stencil copied to clipboard

[stencil] tests for file upload interceptor

Open techsavvyash opened this issue 1 year ago • 11 comments

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

  1. filename is simple: test.txt
  2. file name has multiple periods: text.tar.gz
  3. the service should throw for illegal filenames like: foo/bar.xz or ../foo.txt or foo/../bar.ext
  4. filename without extensions are allowed filename
  5. It is throwing if the STORAGE_ENDPOINT directory does not exist
  6. It is throwing if the destination directory does not exist.
  7. Allowing for files with spaces in the same foo bar.ext
  8. Allows for empty destination parameter and stores in the root of STORAGE_ENDPOINT folder.

Uploading to minIO

Uploads over HTTP (process.env.STORAGE_USE_SSL === false)

  1. The returned urls have http and port number mentioned
  2. All the cases from # Saving to local storage while treating STORAGE_ENDPOINT as the minio endpoint and destination as the bucket name.

Uploads pver HTTPS (process.env.STORAGE_USE_SSL === true)

  1. Returned urls have https always but only contain port numbers in case of direct IPv4 or IPv6 addresses in the STORAGE_ENDPOINT. (For example returned url should look like: https://<IP>:<PORT>/destination/filename)
  2. Returned urls have https but not the port number in case the STORAGE_ENDPOINT is a proper url such as cdn-api.dev.samagra.io. (For example returned url should look like: https://cdn-api.dev.samagra.io/destination/filename)
  3. All the cases from # Saving to local storage while treating STORAGE_ENDPOINT as the minio endpoint and destination as the bucket name.

Make-Bucket Endpoint

  1. Test the make-bucket endpoint for local storage
  2. Test the make-bucket endpoint for minio

Downloads

  1. make sure illegal destination parameters like ../foo/bar are rejected right of the back.
  2. Make sure test case 1 for filenames as well.
  3. 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

techsavvyash avatar Jan 05 '24 04:01 techsavvyash