Skip to content

Commit

Permalink
final commit for local storage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnaaruag committed Jul 15, 2024
1 parent 3396330 commit f22573c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
1 change: 1 addition & 0 deletions sample/04-file-upload/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
68 changes: 34 additions & 34 deletions sample/04-file-upload/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,42 @@ describe('AppController (e2e)', () => {
.expect(200)
.expect('Hello World from file upload.');
});

it('should allow empty destination parameter and store in root of STORAGE_ENDPOINT', async () => {
// const mockFilename = 'testfile1.txt';
// const mockDestination = '';

const response = await request(app.getHttpServer())
.post(`/files/upload-file`)
.query({ filename: 'test.txt' })
.query({ destination: '' })
.attach('file', Buffer.from('content'), 'test.txt');

expect(response.body).toEqual({
message: 'File uploaded successfully',
file: { url: `/${'test.txt'}` },
});
});

it('throws error if destination does not exist', async () => {
const mockDestination = 'notUploads';
const mockFilename = 'content.txt';

try {
await request(app.getHttpServer())
.post(
`/files/upload-file?destination=${mockDestination}&filename=${mockFilename}`,
)
.attach('file', Buffer.from('content'), mockFilename);
} catch (error) {
expect(error.message).toBe(
'Given destination path does not exist. Please create one.',
);
}
});
});

describe('Endpoint/directory tests to ensure correct setup of application', () => {
describe('Test that require mock environment variables', () => {
let app: INestApplication;
const OLD_ENV = process.env;

Expand Down Expand Up @@ -52,37 +85,4 @@ describe('Endpoint/directory tests to ensure correct setup of application', () =
);
}
});

it('throws error if destination does not exist', async () => {
const mockDestination = 'notUploads';
const mockFilename = 'content.txt';

try {
await request(app.getHttpServer())
.post(
`/files/upload-file?destination=${mockDestination}&filename=${mockFilename}`,
)
.attach('file', Buffer.from('content'), mockFilename);
} catch (error) {
console.log(error);
expect(error.message).toBe(
'Given destination path does not exist. Please create one.',
);
}
});

// it('should allow empty destination parameter and store in root of STORAGE_ENDPOINT', async () => {
// // const mockFilename = 'testfile1.txt';
// // const mockDestination = '';

// const response = await request(app.getHttpServer())
// .post(`/files/upload-file?filename=testfile1.txt`)
// .attach('file', Buffer.from('content'), 'testfile1.txt');

// console.log(response);
// expect(response.body).toEqual({
// message: 'File uploaded successfully',
// file: { url: `/${'testfile1.txt'}` },
// });
// });
});

0 comments on commit f22573c

Please sign in to comment.