Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gnaaruag committed Jul 15, 2024
1 parent f22573c commit 709581e
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions sample/04-file-upload/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,42 @@ describe('AppController (e2e)', () => {
.expect(200)
.expect('Hello World from file upload.');
});
});

describe('Test that require mock environment variables', () => {
let app: INestApplication;
const OLD_ENV = process.env;

beforeEach(async () => {
jest.resetModules();
process.env = { ...OLD_ENV };
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
});

afterAll(() => {
process.env = OLD_ENV;
});

it('Throws error if process.env.STORAGE_ENDPOINT is not set up', async () => {
process.env.STORAGE_ENDPOINT = 'this/path/does/not/exist';
try {
await app.init();
} catch (error) {
expect(error.name).toBe('InternalServerErrorException');
expect(error.message).toBe(
'Storage location does not exist. Make sure this location is present and accessible by the application.',
);
}
});

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

await app.init();
const response = await request(app.getHttpServer())
.post(`/files/upload-file`)
.query({ filename: 'test.txt' })
Expand Down Expand Up @@ -55,34 +86,3 @@ describe('AppController (e2e)', () => {
}
});
});

describe('Test that require mock environment variables', () => {
let app: INestApplication;
const OLD_ENV = process.env;

beforeEach(async () => {
jest.resetModules();
process.env = { ...OLD_ENV };
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
});

afterAll(() => {
process.env = OLD_ENV;
});

it('Throws error if process.env.STORAGE_ENDPOINT is not set up', async () => {
process.env.STORAGE_ENDPOINT = 'this/path/does/not/exist';
try {
await app.init();
} catch (error) {
expect(error.name).toBe('InternalServerErrorException');
expect(error.message).toBe(
'Storage location does not exist. Make sure this location is present and accessible by the application.',
);
}
});
});

0 comments on commit 709581e

Please sign in to comment.