Skip to content

Commit

Permalink
add test to prevent #811 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed Aug 15, 2020
1 parent a32abc7 commit 5131ca1
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@
"smart home",
"hb-service"
]
}
}
7 changes: 7 additions & 0 deletions test/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { Test, TestingModule } from '@nestjs/testing';
import { ValidationPipe } from '@nestjs/common';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AppModule } from '../../src/app.module';

Expand Down Expand Up @@ -30,6 +31,12 @@ describe('AppController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();
});
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/auth.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -31,6 +32,12 @@ describe('AuthController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/backup.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -35,6 +36,12 @@ describe('BackupController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/config-editor.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -35,6 +36,12 @@ describe('ConfigEditorController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();
});
Expand Down
77 changes: 77 additions & 0 deletions test/e2e/fastify.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import * as fastify from 'fastify';
import * as fastifyMultipart from 'fastify-multipart';
import * as helmet from 'helmet';
import { AppModule } from '../../src/app.module';

describe('FastifyOptions (e2e)', () => {
let app: NestFastifyApplication;

let authFilePath: string;
let secretsFilePath: string;

beforeAll(async () => {
process.env.UIX_BASE_PATH = path.resolve(__dirname, '../../');
process.env.UIX_STORAGE_PATH = path.resolve(__dirname, '../', '.homebridge');
process.env.UIX_CONFIG_PATH = path.resolve(process.env.UIX_STORAGE_PATH, 'config.json');

authFilePath = path.resolve(process.env.UIX_STORAGE_PATH, 'auth.json');
secretsFilePath = path.resolve(process.env.UIX_STORAGE_PATH, '.uix-secrets');

// setup test config
await fs.copy(path.resolve(__dirname, '../mocks', 'config.json'), process.env.UIX_CONFIG_PATH);

// setup test auth file
await fs.copy(path.resolve(__dirname, '../mocks', 'auth.json'), authFilePath);
await fs.copy(path.resolve(__dirname, '../mocks', '.uix-secrets'), secretsFilePath);

const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

// setup fastify
const server = fastify({
logger: {
prettyPrint: true,
},
});

const fAdapter = new FastifyAdapter(server);

fAdapter.register(fastifyMultipart, {
limits: {
files: 1,
},
});

app = moduleFixture.createNestApplication<NestFastifyApplication>(fAdapter);

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

app.use(helmet());

await app.init();
await app.getHttpAdapter().getInstance().ready();
});

it('GET /', async () => {
const res = await app.inject({
method: 'GET',
path: '/'
});

expect(res.statusCode).toEqual(200);
expect(res.body).toEqual('Hello World!');
});

afterAll(async () => {
await app.close();
});
});
7 changes: 7 additions & 0 deletions test/e2e/platform-tools-docker.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -37,6 +38,12 @@ describe('PlatformToolsDocker (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/platform-tools-hb-service.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -38,6 +39,12 @@ describe('PlatformToolsHbService (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/platform-tools-linux.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -36,6 +37,12 @@ describe('PlatformToolsLinux (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/plugins.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -39,6 +40,12 @@ describe('PluginController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();
});
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/server.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { AuthModule } from '../../src/core/auth/auth.module';
Expand Down Expand Up @@ -40,6 +41,12 @@ describe('ServerController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/status.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { StatusModule } from '../../src/modules/status/status.module';
Expand Down Expand Up @@ -32,6 +33,12 @@ describe('StatusController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();
});
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/users.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { authenticator } from 'otplib';
import { ValidationPipe } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify';
import { UsersModule } from '../../src/modules/users/users.module';
Expand Down Expand Up @@ -33,6 +34,12 @@ describe('UsersController (e2e)', () => {
}).compile();

app = moduleFixture.createNestApplication<NestFastifyApplication>(new FastifyAdapter());

app.useGlobalPipes(new ValidationPipe({
whitelist: true,
skipMissingProperties: true,
}));

await app.init();
await app.getHttpAdapter().getInstance().ready();
});
Expand Down

0 comments on commit 5131ca1

Please sign in to comment.