-
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.
Merge branch 'chore/unit-test-and-linter-fixes' into feat/create-priv…
…ate-folder-permission
- Loading branch information
Showing
9 changed files
with
160 additions
and
40 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ const testUser = { | |
user_id: 'JohnDoe userId', | ||
name: 'John', | ||
lastname: 'Doe', | ||
uuid: v4(), | ||
uuid: '123e4567-e89b-12d3-a456-426614174000', | ||
email: '[email protected]', | ||
username: '[email protected]', | ||
bridge_user: '[email protected]', | ||
|
@@ -26,7 +26,7 @@ const referredTestUser = { | |
user_id: 'JohnDoe userId', | ||
name: 'John', | ||
lastname: 'Doe', | ||
uuid: v4(), | ||
uuid: '09b073a3-ffc0-42dd-aa6a-dea4702bfbd6', | ||
email: '[email protected]', | ||
username: '[email protected]', | ||
bridge_user: '[email protected]', | ||
|
@@ -50,7 +50,7 @@ module.exports = { | |
* name: 'John Doe', | ||
* isBetaMember: false | ||
* }], {}); | ||
*/ | ||
*/ | ||
const existingUsers = await queryInterface.sequelize.query( | ||
'SELECT email FROM users WHERE email IN (:emails)', | ||
{ | ||
|
@@ -75,8 +75,14 @@ module.exports = { | |
* Example: | ||
* await queryInterface.bulkDelete('People', null, {}); | ||
*/ | ||
await queryInterface.bulkDelete('users', { | ||
email: { [Op.in]: [testUser.email, referredTestUser.email] } | ||
}, {}); | ||
} | ||
await queryInterface.bulkDelete( | ||
'users', | ||
{ | ||
email: { [Op.in]: [testUser.email, referredTestUser.email] }, | ||
}, | ||
{}, | ||
); | ||
}, | ||
}; | ||
|
||
module.exports.users = { testUser, referredTestUser }; |
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
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
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
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
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
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
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,80 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { HttpStatus, INestApplication, ValidationPipe } from '@nestjs/common'; | ||
import request from 'supertest'; | ||
|
||
import { TransformInterceptor } from '../../lib/transform.interceptor'; | ||
import { AppModule } from '../../app.module'; | ||
|
||
import { users } from '../../../seeders/20230308180046-test-users.js'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Sign } from '../../middlewares/passport'; | ||
|
||
const user = users.testUser; | ||
|
||
describe('PrivateSharing module', () => { | ||
let app: INestApplication; | ||
let configService: ConfigService; | ||
|
||
function getToken(): string { | ||
return Sign( | ||
{ | ||
payload: { | ||
uuid: user.uuid, | ||
email: user.email, | ||
name: user.name, | ||
lastname: user.lastname, | ||
username: user.username, | ||
sharedWorkspace: true, | ||
networkCredentials: { | ||
user: user.bridgeUser, | ||
pass: user.userId, | ||
}, | ||
}, | ||
}, | ||
configService.get('secrets.jwt'), | ||
true, | ||
); | ||
} | ||
|
||
beforeAll(async () => { | ||
jest.resetModules(); | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
app = moduleFixture.createNestApplication(); | ||
configService = moduleFixture.get<ConfigService>(ConfigService); | ||
app.useGlobalPipes(new ValidationPipe()); | ||
app.useGlobalInterceptors(new TransformInterceptor()); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('/private-sharing/receive/folders (GET)', async () => { | ||
console.log('getToken()', getToken()); | ||
return await request(app.getHttpServer()) | ||
.get('/private-sharing/receive/folders') | ||
.set('Authorization', 'Bearer ' + getToken()) | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it('/private-sharing/sent/folders (GET)', async () => { | ||
return await request(app.getHttpServer()) | ||
.get('/private-sharing/sent/folders') | ||
.set('Authorization', 'Bearer ' + getToken()) | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it('/private-sharing/receive/folders (GET)', async () => { | ||
console.log('getToken()', getToken()); | ||
return await request(app.getHttpServer()) | ||
.get('/private-sharing/receive/folders') | ||
.set('Authorization', 'Bearer ' + getToken()) | ||
.then((response) => { | ||
console.log('Error message:', response.body); | ||
expect(response.status).toEqual(HttpStatus.OK); | ||
}); | ||
}); | ||
}); |
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