-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding segmentcontroller unit test cases and resolved other small iss…
…ues in unit tests (#1729) Co-authored-by: danoswaltCL <[email protected]>
- Loading branch information
1 parent
04bc149
commit 7f59375
Showing
5 changed files
with
212 additions
and
3 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
115 changes: 115 additions & 0 deletions
115
backend/packages/Upgrade/test/unit/controllers/SegmentController.test.ts
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,115 @@ | ||
import app from '../../utils/expressApp'; | ||
import request from 'supertest'; | ||
import { configureLogger } from '../../utils/logger'; | ||
import { useContainer as routingUseContainer } from 'routing-controllers'; | ||
import { Container } from 'typedi'; | ||
import { v4 as uuid } from 'uuid'; | ||
import SegmentServiceMock from './mocks/SegmentServiceMock'; | ||
import { SegmentService } from '../../../src/api/services/SegmentService'; | ||
|
||
import { useContainer as classValidatorUseContainer } from 'class-validator'; | ||
import { useContainer as ormUseContainer } from 'typeorm'; | ||
|
||
describe('Segment Controller Testing', () => { | ||
beforeAll(() => { | ||
configureLogger(); | ||
routingUseContainer(Container); | ||
ormUseContainer(Container); | ||
classValidatorUseContainer(Container); | ||
|
||
// set mock container | ||
Container.set(SegmentService, new SegmentServiceMock()); | ||
}); | ||
|
||
afterAll(() => { | ||
Container.reset(); | ||
}); | ||
|
||
const segmentData = { | ||
id: uuid(), | ||
name: "segment1", | ||
description: "desc", | ||
context: "home", | ||
type: "public", | ||
status: "Unused", | ||
userIds: ["user1"], | ||
groups: { | ||
groupId : "group1", | ||
type: "school" | ||
}, | ||
subSegmentIds: ["seg2"] | ||
}; | ||
|
||
test('Get request for /api/segments', () => { | ||
return request(app) | ||
.get('/api/segments') | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Get request for /api/segments/:segmentId', () => { | ||
return request(app) | ||
.get(`/api/segments/${uuid()}`) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Get request for /api/segments/status/:segmentId', () => { | ||
return request(app) | ||
.get(`/api/segments/status/${uuid()}`) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Post request for /api/segments', () => { | ||
return request(app) | ||
.post('/api/segments') | ||
.send([segmentData]) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Delete request for /api/segments/:segmentId', () => { | ||
return request(app).delete(`/api/segments/${uuid()}`).expect('Content-Type', /json/).expect(200); | ||
}); | ||
|
||
test('Post request for /api/segments/import', () => { | ||
return request(app) | ||
.post('/api/segments/import') | ||
.send(segmentData) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Post request for /api/segments/validation', () => { | ||
return request(app).post('/api/segments/validation').send(segmentData).expect('Content-Type', /json/).expect(200); | ||
}); | ||
|
||
test('Get request for /api/segments/export/json', () => { | ||
return request(app) | ||
.get('/api/segments/export/json') | ||
.query({ | ||
ids: [uuid()], | ||
}) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('Get request for /api/segments/export/csv', () => { | ||
return request(app) | ||
.get('/api/segments/export/csv') | ||
.query({ | ||
ids: [uuid()], | ||
}) | ||
.set('Accept', 'application/json') | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
}); |
52 changes: 52 additions & 0 deletions
52
backend/packages/Upgrade/test/unit/controllers/mocks/SegmentServiceMock.ts
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,52 @@ | ||
import { Service } from 'typedi'; | ||
|
||
@Service() | ||
export default class ExcludeServiceMock { | ||
public getAllSegments(): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public getAllSegmentWithStatus(): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public getSegmentById(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public getSegmentWithStatusById(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public getSingleSegmentWithStatus(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public upsertSegment(): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public importSegments(): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public deleteSegment(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public validateSegments(): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public exportSegments(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public exportSegment(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
|
||
public exportSegmentCSV(id: string): Promise<[]> { | ||
return Promise.resolve([]); | ||
} | ||
} |