Open techsavvyash opened 10 months ago
Hi! Important Details - These following details are helpful for contributors to effectively identify and contribute to tickets.
Please update the ticket
Hey @techsavvyash i am familiar with jest can i work on this?
Please go ahead @Min2who assigning this to you
Hi @techsavvyash sir as I was working on integrating bun.js ,I came across this issue and I think it is solvable shall i try
Hey @vsvishalsharma, This is being already worked upon, I suggest you focus on the Bun.js ticket itself.
@techsavvyash sure sir
@techsavvyash I understand the problem, and I believe I have the necessary skills. Could I have the opportunity to work on this?
@techsavvyash this is the initial code i have implemented:
`import { ExecutionContext } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { Observable,of } from 'rxjs';
import { FastifyFileInterceptor } from '../src/interceptors/file-upload.interceptor';
describe('FastifyFileInterceptor', () => {
let interceptor: FastifyFileInterceptor;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [FastifyFileInterceptor],
}).compile();
interceptor = module.get<FastifyFileInterceptor>(FastifyFileInterceptor);
});
it('should be defined', () => {
expect(interceptor).toBeDefined();
});
it('should handle file upload', async () => {
const context: ExecutionContext = {
switchToHttp: jest.fn(() => ({
getRequest: jest.fn(() => ({
file: {},
})),
getResponse: jest.fn(),
})),
switchToRpc: jest.fn(),
switchToWs: jest.fn(),
};
const nextHandler = {
handle: jest.fn(() => of('')),
};
await interceptor.intercept(context, nextHandler);
expect(context.switchToHttp().getRequest).toHaveBeenCalled();
expect(context.switchToHttp().getResponse).toHaveBeenCalled();
expect(nextHandler.handle).toHaveBeenCalled();
});
it('should handle getting an uploaded file', async () => {
const file = { /* mock file object */ };
const context: ExecutionContext = {
switchToHttp: jest.fn(() => ({
getRequest: jest.fn(() => ({
file: file,
})),
getResponse: jest.fn(),
})),
switchToRpc: jest.fn(),
switchToWs: jest.fn(),
};
const nextHandler = {
handle: jest.fn(() => of('')),
};
await interceptor.intercept(context, nextHandler);
expect(context.switchToHttp().getRequest).toHaveBeenCalled();
expect(context.switchToHttp().getResponse).toHaveBeenCalled();
// Assert that the uploaded file is passed to the next handler
expect(nextHandler.handle).toHaveBeenCalledWith(file);
});
it('should handle errors', async () => {
const context: ExecutionContext = {
switchToHttp: jest.fn(() => ({
getRequest: jest.fn(() => ({
file: {},
})),
getResponse: jest.fn(),
})),
switchToRpc: jest.fn(),
switchToWs: jest.fn(),
};
const errorMessage = 'File upload failed';
const nextHandler = {
handle: jest.fn(() => throwError(errorMessage)),
};
try {
await interceptor.intercept(context, nextHandler);
} catch (error) {
expect(error.message).toBe(errorMessage);
}
expect(context.switchToHttp().getRequest).toHaveBeenCalled();
expect(context.switchToHttp().getResponse).toHaveBeenCalled();
expect(nextHandler.handle).toHaveBeenCalled();
});
});
`
@vsvishalsharma please go ahead and raise a draft PR
Hey @techsavvyash I also tried my hands on it and I guess I have pretty much done the required task Can you please assign this to me and can I raise the PR fo it ?
hey @deecodess if you have tests ready, please raise a PR. This is a long running test case and we only assign issues once a draft PR has been raised.
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
file-upload
interceptorImplementational Details
Create a test file named
file-upload.interceptor.spec.ts
in the tests directory and write the required test cases usingjest
. 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
test.txt
text.tar.gz
foo/bar.xz
or../foo.txt
orfoo/../bar.ext
filename
STORAGE_ENDPOINT
directory does not existdestination
directory does not exist.foo bar.ext
destination
parameter and stores in the root ofSTORAGE_ENDPOINT
folder.Uploading to minIO
Uploads over HTTP (
process.env.STORAGE_USE_SSL
=== false)http
and port number mentioned# 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)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
)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
)# Saving to local storage
while treatingSTORAGE_ENDPOINT
as the minio endpoint anddestination
as the bucket name.Make-Bucket Endpoint
make-bucket
endpoint forlocal storage
make-bucket
endpoint forminio
Downloads
destination
parameters like../foo/bar
are rejected right of the back.filenames
as well.Ad-Hoc