Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
c27gc committed Jul 11, 2023
1 parent 70734b5 commit cf90cd8
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/modules/private-share-folder/private-sharing.e2e.ts
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;
let expressInstance;

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();
expressInstance = app.getHttpAdapter().getInstance();
});

afterAll(async () => {
await app.close();
});

it('/private-sharing/receive/folders (GET)', async () => {
return await request(expressInstance)
.get('/private-sharing/receive/folders')
.set('Authorization', 'Bearer ' + getToken())
.expect(HttpStatus.OK);
});

it('/private-sharing/sent/folders (GET)', async () => {
return await request(expressInstance)
.get('/private-sharing/sent/folders')
.set('Authorization', 'Bearer ' + getToken())
.expect(HttpStatus.OK);
});

it('/private-sharing/receive/folders (GET)', async () => {
return await request(expressInstance)
.get('/private-sharing/receive/folders')
.set('Authorization', 'Bearer ' + getToken())
.then((response) => {
console.log('Error message:', response.body);
expect(response.status).toEqual(HttpStatus.OK);
});
});
});

0 comments on commit cf90cd8

Please sign in to comment.