@nestjs/core#NestApplication TypeScript Examples
The following examples show how to use
@nestjs/core#NestApplication.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dependency-check.service.e2e-spec.ts From barista with Apache License 2.0 | 4 votes |
describe('Dependency Check Service (e2e)', () => {
let app: NestApplication;
let service: DependencyCheckService;
let job: DefaultScanWorkerJobInfo;
let scanService;
let projectService;
let project;
let scan;
beforeEach(async (done) => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
AppOrmModule,
ServicesModule,
],
providers: [
DependencyCheckService,
DefaultScanWorkerService,
LicenseCheckerService,
LicenseMavenService,
LicenseNugetService,
ProjectService,
ScanService,
ScanCodeService,
MavenService,
NpmService,
NugetService,
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
service = app.get(DependencyCheckService);
scanService = app.get(ScanService);
projectService = app.get(ProjectService);
done();
});
it('Instantiates the service', () => {
expect(service).toBeInstanceOf(DependencyCheckService);
});
describe('vulnerability tests', () => {
beforeEach(async (done) => {
// Create necessary scans
project = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
scan = await scanService.db.save({ project });
job = TestHelper.testJobInfo({ scanId: scan.id });
// Copy test data to the temp directory
shell.cp('-R', `${TestHelper.insecureSampleProject}/*`, job.tmpDir);
done();
});
it('detects vulnerabilities', async (done) => {
jest.setTimeout(30000);
expect(service).toBeInstanceOf(DependencyCheckService);
// Execute Scan
await service.execute(job);
// const scan: Scan = await scanService.findOne(job.scanId);
const actual: SecurityScanResult = await SecurityScanResult.findOne({
where: { scanId: scan.id },
join: {
alias: 'result',
leftJoinAndSelect: {
scan: 'result.scan',
},
},
},
);
expect(actual).toBeDefined();
expect(actual.startedAt).toBeInstanceOf(Date);
expect(actual.completedAt).toBeInstanceOf(Date);
expect(actual.startedAt).not.toEqual(actual.completedAt);
expect(actual.htmlResults).toBeDefined();
expect(actual.htmlResults).not.toBeNull();
expect(actual.jsonResults).toBeDefined();
expect(actual.jsonResults).not.toEqual('');
expect(actual.scan).toBeDefined();
done();
});
afterEach(async (done) => {
// await projectService.db.delete({});
await projectService.db.remove(project);
done();
});
});
afterEach(async (done) => {
await app.close();
done();
});
});
Example #2
Source File: license-checker.service.e2e-spec.ts From barista with Apache License 2.0 | 4 votes |
describe('License Checker Service (e2e)', () => {
let app: NestApplication;
let licenseCheckerService: LicenseCheckerService;
let job: DefaultScanWorkerJobInfo;
let scanService;
let projectService;
let project;
let scan;
beforeEach(async (done) => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
AppOrmModule,
ServicesModule,
],
providers: [
DependencyCheckService,
DefaultScanWorkerService,
LicenseScanResultItemService,
LicenseService,
ProjectService,
ScanService,
ScanCodeService,
LicenseCheckerService,
LicenseMavenService,
LicenseNugetService,
MavenService,
NpmService,
NugetService,
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
licenseCheckerService = app.get(LicenseCheckerService);
scanService = app.get(ScanService);
projectService = app.get(ProjectService);
done();
});
it('Instantiates the service', () => {
expect(licenseCheckerService).toBeInstanceOf(LicenseCheckerService);
});
describe('License tests', () => {
beforeEach(async (done) => {
// Create necessary scans
project = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
scan = await scanService.db.save({ project, deploymentType: { code: 'distributed'} });
job = TestHelper.testJobInfo({ scanId: scan.id });
// Copy test data to the temp directory
shell.cp('-R', `${TestHelper.insecureSampleProject}/*`, job.tmpDir);
done();
});
it('executes license checker', async (done) => {
jest.setTimeout(20000);
expect(licenseCheckerService).toBeInstanceOf(LicenseCheckerService);
// Execute Scan
await licenseCheckerService.execute(job);
const actual = await scanService.db.createQueryBuilder('scan')
.leftJoinAndSelect('scan.licenseScanResults', 'licenseScanResults')
.leftJoinAndSelect('licenseScanResults.licenseScanResultItems', 'licenseScanResults.licenseScanResultItems')
.whereInIds(job.scanId)
.getOne();
expect(actual).toBeDefined();
expect(actual.licenseScanResults.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].startedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].completedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].startedAt).not.toEqual(actual.licenseScanResults[0].completedAt);
expect(actual.licenseScanResults[0].licenseScanResultItems).toBeDefined();
expect(actual.licenseScanResults[0].jsonResults).toBeInstanceOf(Object);
expect(actual.licenseScanResults[0].licenseScanResultItems.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].licenseScanResultItems[0].path).toBeDefined();
expect(job.errors.length).toBe(0);
done();
});
});
afterEach(async () => {
// await projectService.db.delete({});
return app.close();
});
});
Example #3
Source File: license-maven.service.e2e-spec.ts From barista with Apache License 2.0 | 4 votes |
describe('License Maven Service (e2e)', () => {
let app: NestApplication;
let licenseMavenService: LicenseMavenService;
let job: DefaultScanWorkerJobInfo;
let scanService;
let projectService;
let project;
let scan;
beforeEach(async (done) => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
AppOrmModule,
ServicesModule,
],
providers: [
LicenseMavenService,
ScanService,
LicenseService,
LicenseScanResultService,
LicenseScanResultItemService,
{ provide: 'DefaultScanWorkerService', useClass: jest.fn() },
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
licenseMavenService = app.get(LicenseMavenService);
scanService = app.get(ScanService);
projectService = app.get(ProjectService);
done();
});
it('Instantiates the service', () => {
expect(licenseMavenService).toBeInstanceOf(LicenseMavenService);
});
describe('License tests', () => {
beforeEach(async (done) => {
// Create necessary scans
project = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
scan = await scanService.db.save({ project, deploymentType: { code: 'distributed'} });
job = TestHelper.testJobInfo({ scanId: scan.id });
// Copy test data to the temp directory
shell.cp('-R', `${TestHelper.mavenSampleProject}/*`, job.tmpDir);
done();
});
it('executes license maven', async (done) => {
jest.setTimeout(920000);
expect(licenseMavenService).toBeInstanceOf(LicenseMavenService);
// Execute Scan
await licenseMavenService.execute(job);
const actual = await scanService.db.createQueryBuilder('scan')
.leftJoinAndSelect('scan.licenseScanResults', 'licenseScanResults')
.leftJoinAndSelect('licenseScanResults.licenseScanResultItems', 'licenseScanResults.licenseScanResultItems')
.whereInIds(job.scanId)
.getOne();
expect(actual).toBeDefined();
expect(actual.licenseScanResults.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].startedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].completedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].startedAt).not.toEqual(actual.licenseScanResults[0].completedAt);
expect(actual.licenseScanResults[0].licenseScanResultItems).toBeDefined();
expect(actual.licenseScanResults[0].jsonResults).toBeInstanceOf(Object);
expect(actual.licenseScanResults[0].licenseScanResultItems.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].licenseScanResultItems[0].path).toBeDefined();
expect(job.errors.length).toBe(0);
done();
});
});
afterEach(async () => {
// await projectService.db.delete({});
return app.close();
});
});
Example #4
Source File: license-nuget.service.e2e-spec.ts From barista with Apache License 2.0 | 4 votes |
describe('License Nuget Service (e2e)', () => {
let app: NestApplication;
let licenseNugetService: LicenseNugetService;
let job: DefaultScanWorkerJobInfo;
let scanService;
let projectService;
let project;
let scan;
beforeEach(async (done) => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
AppOrmModule,
ServicesModule,
],
providers: [
DependencyCheckService,
DefaultScanWorkerService,
LicenseCheckerService,
LicenseScanResultItemService,
LicenseService,
ProjectService,
ScanService,
ScanCodeService,
LicenseNugetService,
LicenseMavenService,
MavenService,
NpmService,
NugetService,
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
licenseNugetService = app.get(LicenseNugetService);
scanService = app.get(ScanService);
projectService = app.get(ProjectService);
done();
});
it('Instantiates the service', () => {
expect(licenseNugetService).toBeInstanceOf(LicenseNugetService);
});
describe('License tests', () => {
beforeEach(async (done) => {
// Create necessary scans
project = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
scan = await scanService.db.save({ project, deploymentType: { code: 'distributed'} });
job = TestHelper.testJobInfo({ scanId: scan.id });
// Copy test data to the temp directory
shell.cp('-R', `${TestHelper.nugetSampleProject}/*`, job.tmpDir);
done();
});
it('executes license nuget', async (done) => {
jest.setTimeout(920000);
expect(licenseNugetService).toBeInstanceOf(LicenseNugetService);
// Execute Scan
await licenseNugetService.execute(job);
const actual = await scanService.db.createQueryBuilder('scan')
.leftJoinAndSelect('scan.licenseScanResults', 'licenseScanResults')
.leftJoinAndSelect('licenseScanResults.licenseScanResultItems', 'licenseScanResults.licenseScanResultItems')
.whereInIds(job.scanId)
.getOne();
expect(actual).toBeDefined();
expect(actual.licenseScanResults.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].startedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].completedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].startedAt).not.toEqual(actual.licenseScanResults[0].completedAt);
expect(actual.licenseScanResults[0].licenseScanResultItems).toBeDefined();
expect(actual.licenseScanResults[0].jsonResults).toBeInstanceOf(Object);
expect(actual.licenseScanResults[0].licenseScanResultItems.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].licenseScanResultItems[0].path).toBeDefined();
expect(job.errors.length).toBe(0);
done();
});
});
afterEach(async () => {
// await projectService.db.delete({});
return app.close();
});
});
Example #5
Source File: scan-code.service.e2e-spec.ts From barista with Apache License 2.0 | 4 votes |
describe('Scan Code Service (e2e)', () => {
let app: NestApplication;
let scanCodeService: ScanCodeService;
let job: DefaultScanWorkerJobInfo;
let scanService;
let projectService;
let project;
let scan;
let licenseService;
let licenseScanResultService;
beforeEach(async (done) => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
AppOrmModule,
ServicesModule,
],
providers: [
DependencyCheckService,
DefaultScanWorkerService,
LicenseScanResultItemService,
LicenseScanResultService,
LicenseNugetService,
LicenseMavenService,
LicenseCheckerService,
LicenseService,
ProjectService,
ScanService,
ScanCodeService,
MavenService,
NpmService,
NugetService,
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
scanCodeService = app.get(ScanCodeService);
scanService = app.get(ScanService);
projectService = app.get(ProjectService);
licenseService = app.get(LicenseService);
licenseScanResultService = app.get(LicenseScanResultService);
done();
});
it('Instantiates the service', () => {
expect(scanCodeService).toBeInstanceOf(ScanCodeService);
});
describe('License Tests', () => {
let actual;
const input = {
key: 'lgpl-2.1-plus',
score: 100.0,
name: 'GNU Lesser General Public License 2.1 or later',
short_name: 'LGPL 2.1 or later',
category: 'Copyleft Limited',
is_exception: false,
owner: 'Free Software Foundation (FSF)',
homepage_url: 'http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html',
text_url: 'http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html',
reference_url: 'https://enterprise.dejacode.com/urn/urn:dje:license:lgpl-2.1-plus',
spdx_license_key: 'LGPL-2.1-or-later',
spdx_url: 'https://spdx.org/licenses/LGPL-2.1-or-later',
start_line: 1,
end_line: 502,
matched_rule: {
identifier: 'lgpl-2.1-plus_2.RULE',
license_expression: 'lgpl-2.1-plus',
licenses: [
'lgpl-2.1-plus',
],
is_license_text: false,
is_license_notice: true,
is_license_reference: false,
is_license_tag: false,
},
};
it('should create a license', async (done) => {
actual = await scanCodeService.createLicense(input);
expect(actual).toBeDefined();
expect(actual).toBeInstanceOf(Object);
expect(actual.id).toBeGreaterThan(0);
done();
});
it('should upsert a license', async (done) => {
actual = await scanCodeService.upsertLicense(input);
const expected = await scanCodeService.upsertLicense(input);
expect(actual.id).toBe(expected.id);
done();
});
afterEach(async (done) => {
await licenseService.db.remove(actual);
done();
});
});
describe('license tests', () => {
beforeEach(async (done) => {
// Create necessary scans
project = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
scan = await scanService.db.save({ project, deploymentType: { code: 'distributed'} });
job = TestHelper.testJobInfo({ scanId: scan.id });
// Copy test data to the temp directory
shell.cp('-R', `${TestHelper.licenseSampleProject}/*`, job.tmpDir);
done();
});
it('executes scan code', async (done) => {
jest.setTimeout(40000);
expect(scanCodeService).toBeInstanceOf(ScanCodeService);
// Execute Scan
await scanCodeService.execute(job);
const actual = await scanService.db.createQueryBuilder('scan')
.leftJoinAndSelect('scan.licenseScanResults', 'licenseScanResults')
.leftJoinAndSelect('licenseScanResults.licenseScanResultItems', 'licenseScanResults.licenseScanResultItems')
.whereInIds(job.scanId)
.getOne();
expect(actual.licenseScanResults.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].startedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].completedAt).toBeInstanceOf(Date);
expect(actual.licenseScanResults[0].startedAt).not.toEqual(actual.licenseScanResults[0].completedAt);
expect(actual.licenseScanResults[0].licenseScanResultItems).toBeDefined();
expect(actual.licenseScanResults[0].jsonResults).toBeInstanceOf(Object);
expect(actual.licenseScanResults[0].licenseScanResultItems.length).toBeGreaterThan(0);
expect(actual.licenseScanResults[0].licenseScanResultItems[0].path).toBeDefined();
// TODO: Re-enable these when obligations are fixed
/*
const licenseScan = await LicenseScanResult.getRepository().findOne(actual.licenseScanResults[0].id);
const obligations = await licenseScan.distinctObligations();
expect(obligations).toBeDefined();
expect(obligations).toBeInstanceOf(Object);
expect(obligations.length).toBeGreaterThan(0);
expect(obligations[0].name).toBeDefined();
*/
expect(job.errors.length).toBe(0);
done();
});
xit('returns obligations', async (done) => {
// Note: This test seems to be failing from time to time. It might have something to do with the
// License -> Obligation maps not being recorded consistently on DB resets.
const savedProject = await projectService.db.save({ name: 'test-project', gitUrl: 'http://github.com/test-project' });
project = await projectService.db.findOne(savedProject.id);
const savedScan = await scanService.db.save({ project, completedAt: new Date() });
scan = await scanService.db.findOne(savedScan.id);
await new Promise((resolve) => {
setTimeout(async () => {
await TestHelper.createLicenseScan(scan);
resolve();
}, 1234);
});
await new Promise((resolve) => {
setTimeout(async () => {
await TestHelper.createLicenseScan(scan);
resolve();
}, 1234);
});
let licenseScanResult1: LicenseScanResult = null;
await new Promise((resolve) => {
setTimeout(async () => {
licenseScanResult1 = await TestHelper.createLicenseScan(scan);
resolve();
}, 1234);
});
// Add several licenses with duplicates
await TestHelper.createLicenseScanResult(licenseScanResult1, 1);
await TestHelper.createLicenseScanResult(licenseScanResult1, 1);
await TestHelper.createLicenseScanResult(licenseScanResult1, 2);
await TestHelper.createLicenseScanResult(licenseScanResult1, 2);
await TestHelper.createLicenseScanResult(licenseScanResult1, 3);
await TestHelper.createLicenseScanResult(licenseScanResult1, 3);
await TestHelper.createLicenseScanResult(licenseScanResult1, 4);
await TestHelper.createLicenseScanResult(licenseScanResult1, 4);
expect(licenseScanResult1.licenseScanResultItems.length).toBeGreaterThan(0);
let actual = await licenseScanResultService.distinctObligations(licenseScanResult1);
const expected = [
await Obligation.getRepository().findOne(1),
await Obligation.getRepository().findOne(2),
await Obligation.getRepository().findOne(3),
await Obligation.getRepository().findOne(4),
await Obligation.getRepository().findOne(6),
await Obligation.getRepository().findOne(8),
];
expect(actual.length).toBe(expected.length);
expect(actual).toEqual(expected);
actual = await scan.obligations();
expect(actual).toEqual(expected);
actual = await project.obligations();
expect(actual).toEqual(expected);
done();
});
});
afterEach(async () => {
// await projectService.db.delete({});
return app.close();
});
});