Skip to content

Commit

Permalink
test: basic s3 upload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasdc committed Sep 16, 2024
1 parent 02a1373 commit 30fbdec
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions app/tests/backend/lib/s3upload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @jest-environment node
*/
import { mocked } from 'jest-mock';
import request from 'supertest';
import express from 'express';
import session from 'express-session';
import crypto from 'crypto';
import s3upload from 'backend/lib/s3upload';
import getAuthRole from '../../../utils/getAuthRole';

jest.mock('../../../backend/lib/graphql');
jest.mock('../../../utils/getAuthRole');

jest.mock('../../../backend/lib/s3client', () => {
return {
s3ClientV3: jest.fn().mockImplementation(() => {}),
uploadFileToS3: () => {
return new Promise((resolve) => {
resolve(true);
});
},
};
});

jest.setTimeout(10000000);

describe('The s3 download', () => {
let app;

beforeEach(async () => {
app = express();
app.use(session({ secret: crypto.randomUUID(), cookie: { secure: true } }));

Check failure

Code scanning / CodeQL

Missing CSRF middleware High test

This cookie middleware is serving a
request handler
without CSRF protection.
app.use('/', s3upload);
});

it('should receive the correct response for unauthorized user', async () => {
mocked(getAuthRole).mockImplementation(() => {
return {
pgRole: 'ccbc_guest',
landingRoute: '/',
};
});

const response = await request(app).get('/api/s3/download/test/test');
expect(response.status).toBe(404);
});

it('should receive the correct response for auth user', async () => {
mocked(getAuthRole).mockImplementation(() => {
return {
pgRole: 'ccbc_auth_user',
landingRoute: '/',
};
});

const response = await request(app).post('/api/s3/upload');
expect(response.status).toBe(200);
});

jest.resetAllMocks();
});

0 comments on commit 30fbdec

Please sign in to comment.