-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from jhipster/feature/e2e
Feature/e2e
- Loading branch information
Showing
38 changed files
with
566 additions
and
160 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
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
108 changes: 108 additions & 0 deletions
108
generators/entity-server/templates/server/e2e/entity.e2e-spec.ts.ejs
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,108 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import request = require('supertest'); | ||
import { AppModule } from '../src/app.module'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { AuthGuard } from '../src/security/guards/auth.guard'; | ||
import { RolesGuard } from '../src/security/guards/roles.guard'; | ||
import <%= entityClass %> from '../src/domain/<%= entityFileName %>.entity'; | ||
import { <%= entityClass %>Service } from '../src/service/<%= entityFileName %>.service'; | ||
|
||
describe('<%= entityClass %> Controller', () => { | ||
let app: INestApplication; | ||
|
||
const authGuardMock = { canActivate: (): any => true }; | ||
const rolesGuardMock = { canActivate: (): any => true }; | ||
const entityMock: any = { | ||
id: 'entityId' | ||
} | ||
|
||
const serviceMock = { | ||
findById: (): any => entityMock, | ||
findAndCount: (): any => [entityMock, 0], | ||
save: (): any => entityMock, | ||
update: (): any => entityMock, | ||
delete: (): any => entityMock | ||
}; | ||
|
||
|
||
beforeEach(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).overrideGuard(AuthGuard) | ||
.useValue(authGuardMock) | ||
.overrideGuard(RolesGuard) | ||
.useValue(rolesGuardMock) | ||
.overrideProvider(<%= entityClass %>Service) | ||
.useValue(serviceMock) | ||
.compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
it('/GET all <%= entityApiUrl %> ', async () => { | ||
|
||
const getEntities: <%= entityClass %>[] = (await request(app.getHttpServer()) | ||
.get('/api/<%= entityApiUrl %>') | ||
.expect(200)).body; | ||
|
||
expect(getEntities).toEqual(entityMock); | ||
|
||
} | ||
); | ||
|
||
it('/GET <%= entityApiUrl %> by id', async () => { | ||
|
||
|
||
const getEntity: <%= entityClass %> = (await request(app.getHttpServer()) | ||
.get('/api/<%= entityApiUrl %>/' + entityMock.id) | ||
.expect(200)).body; | ||
|
||
expect(getEntity).toEqual(entityMock); | ||
|
||
} | ||
); | ||
|
||
it('/POST create <%= entityApiUrl %>', async () => { | ||
|
||
const createdEntity: <%= entityClass %> = (await request(app.getHttpServer()) | ||
.post('/api/<%= entityApiUrl %>') | ||
.send(entityMock) | ||
.expect(201)).body; | ||
|
||
expect(createdEntity).toEqual(entityMock); | ||
|
||
} | ||
); | ||
|
||
it('/PUT update <%= entityApiUrl %>', async () => { | ||
|
||
|
||
const updatedEntity: <%= entityClass %> = (await request(app.getHttpServer()) | ||
.put('/api/<%= entityApiUrl %>') | ||
.send(entityMock) | ||
.expect(201)).body; | ||
|
||
|
||
expect(updatedEntity).toEqual(entityMock); | ||
|
||
} | ||
); | ||
|
||
|
||
it('/DELETE <%= entityApiUrl %>', async () => { | ||
|
||
|
||
const deletedEntity: <%= entityClass %> = (await request(app.getHttpServer()) | ||
.delete('/api/<%= entityApiUrl %>/' + entityMock.id) | ||
.expect(204)).body; | ||
|
||
expect(deletedEntity).toEqual({}); | ||
} | ||
); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); | ||
|
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
1 change: 0 additions & 1 deletion
1
generators/entity-server/templates/server/src/service/README.md.ejs
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
generators/entity-server/templates/server/src/service/entity.service.ts.ejs
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,38 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { FindManyOptions, FindOneOptions } from 'typeorm'; | ||
import <%= entityClass %> from '../domain/<%= entityFileName %>.entity'; | ||
import { <%= entityClass %>Repository } from '../repository/<%= entityFileName %>.repository'; | ||
|
||
|
||
@Injectable() | ||
export class <%= entityClass %>Service { | ||
logger = new Logger('<%= entityClass %>Service'); | ||
|
||
constructor(@InjectRepository(<%= entityClass %>Repository) private <%= asEntity(entityInstance) %>Repository: <%= entityClass %>Repository) {} | ||
|
||
async findById(id: string): Promise<<%= entityClass %> | undefined> { | ||
return await this.<%= asEntity(entityInstance) %>Repository.findOne(id); | ||
} | ||
|
||
async findByfields(options: FindOneOptions<<%= entityClass %>>): Promise<<%= entityClass %> | undefined> { | ||
return await this.<%= asEntity(entityInstance) %>Repository.findOne(options); | ||
} | ||
|
||
async findAndCount(options: FindManyOptions<<%= entityClass %>>): Promise<[<%= entityClass %>[], number]> { | ||
return await this.<%= asEntity(entityInstance) %>Repository.findAndCount(options); | ||
} | ||
|
||
async save(<%= asEntity(entityInstance) %>: <%= entityClass %>): Promise<<%= entityClass %> | undefined> { | ||
return await this.<%= asEntity(entityInstance) %>Repository.save(<%= asEntity(entityInstance) %>); | ||
} | ||
|
||
async update(<%= asEntity(entityInstance) %>: <%= entityClass %>): Promise<<%= entityClass %> | undefined> { | ||
return await this.save(<%= asEntity(entityInstance) %>); | ||
} | ||
|
||
async delete(<%= asEntity(entityInstance) %>: <%= entityClass %>): Promise<<%= entityClass %> | undefined> { | ||
return await this.<%= asEntity(entityInstance) %>Repository.remove(<%= asEntity(entityInstance) %>); | ||
} | ||
|
||
} |
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
20 changes: 0 additions & 20 deletions
20
generators/entity-server/templates/server/test/entities/entity.controller.spec.ts.ejs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.