-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Error loading related location Loading |
||
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(); | ||
}); |