-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test for rest in es6 * issue with singleton not working for es6 fixed
- Loading branch information
1 parent
76db286
commit 724e717
Showing
15 changed files
with
2,756 additions
and
389 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
example/rest/javascript/controllers/default_controller.test.js
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,22 @@ | ||
import { DefaultController } from "./default_controller"; | ||
import { viewResult, Fort } from "fortjs"; | ||
import { createApp } from "../index"; | ||
|
||
describe('DefaultController', () => { | ||
let app; | ||
beforeAll(async () => { | ||
app = await createApp(); | ||
}); | ||
|
||
it('index', async () => { | ||
const expectedResult = await viewResult('default/index.html', { | ||
title: 'FortJs' | ||
}); | ||
const indexMethodOutput = await new DefaultController().index('FortJs'); | ||
expect(indexMethodOutput).toEqual(expectedResult); | ||
}); | ||
|
||
afterAll(() => { | ||
return app.destroy(); | ||
}); | ||
}); |
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
23 changes: 23 additions & 0 deletions
23
example/rest/javascript/controllers/user_controller.test.js
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,23 @@ | ||
import { jsonResult } from "fortjs"; | ||
import { createApp } from "../index"; | ||
import { UserController } from "./user_controller"; | ||
import { UserService } from "../services/user_service"; | ||
|
||
describe('UserController', () => { | ||
let app; | ||
let controller; | ||
beforeAll(async () => { | ||
app = await createApp(); | ||
controller = new UserController(new UserService()); | ||
}); | ||
|
||
it('getUsers', async () => { | ||
const expectedResult = await jsonResult(controller.service.getUsers()); | ||
const indexMethodOutput = await controller.getUsers(); | ||
expect(indexMethodOutput).toEqual(expectedResult); | ||
}); | ||
|
||
afterAll(() => { | ||
return app.destroy(); | ||
}); | ||
}); |
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,30 @@ | ||
import axios from "axios"; | ||
import { createApp } from ".."; | ||
const instance = axios.create({ | ||
baseURL: 'http://localhost:4000', | ||
timeout: 1000 | ||
}); | ||
|
||
describe('/default', () => { | ||
|
||
let app; | ||
beforeAll(async () => { | ||
app = await createApp(); | ||
}); | ||
|
||
it('index', async () => { | ||
const response = await instance.get('/', { | ||
headers: { | ||
accept: 'text/html' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.headers['content-type']).toEqual('text/html'); | ||
expect(response.data).toContain('<title>FortJs</title>'); | ||
}); | ||
|
||
afterAll(() => { | ||
return app.destroy(); | ||
}); | ||
|
||
}); |
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,129 @@ | ||
import axios from "axios"; | ||
import { createApp } from "../index"; | ||
|
||
const instance = axios.create({ | ||
baseURL: 'http://localhost:4000/user', | ||
timeout: 1000 | ||
}); | ||
|
||
describe('/user', () => { | ||
|
||
let app; | ||
beforeAll(async () => { | ||
app = await createApp(); | ||
}); | ||
|
||
it('/get all users', async () => { | ||
const response = await instance.get('/', { | ||
headers: { | ||
accept: 'application/json' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.headers['content-type']).toEqual('application/json'); | ||
expect(response.data).toEqual([ | ||
{ "address": "bhubaneswar india", "emailId": "ujjwal@mg.com", "gender": "male", "id": 1, "name": "ujjwal", "password": "admin" } | ||
]); | ||
}); | ||
|
||
it('/get single user', async () => { | ||
const response = await instance.get('/1', { | ||
headers: { | ||
accept: 'application/json' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.headers['content-type']).toEqual('application/json'); | ||
expect(response.data).toEqual( | ||
{ "address": "bhubaneswar india", "emailId": "ujjwal@mg.com", "gender": "male", "id": 1, "name": "ujjwal", "password": "admin" } | ||
); | ||
}); | ||
|
||
it('/add user', async () => { | ||
const user = { | ||
"name": "ujjwal", | ||
"emailId": "ujjwal@m.com", | ||
"password": "12345as", | ||
"gender": "male", | ||
"address": "sadfsgbhfgtbrg" | ||
}; | ||
const response = await instance.post('/', user, { | ||
headers: { | ||
accept: 'application/json' | ||
} | ||
}); | ||
expect(response.status).toEqual(201); | ||
expect(response.headers['content-type']).toEqual('application/json'); | ||
|
||
expect(response.data).toEqual({ id: 2, ...user }); | ||
}); | ||
|
||
it('/update user', async () => { | ||
const user = { | ||
"name": "ujjwal gupta", | ||
"emailId": "ujjwal@m.com", | ||
"password": "12345as", | ||
"gender": "male", | ||
"address": "sadfsgbhfgtbrg", | ||
"id": 2 | ||
}; | ||
const response = await instance.put('/', user, { | ||
headers: { | ||
accept: '*/*' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.data).toEqual("user updated"); | ||
}); | ||
|
||
it('/check updated user', async () => { | ||
const user = { | ||
"name": "ujjwal gupta", | ||
"emailId": "ujjwal@m.com", | ||
"password": "12345as", | ||
"gender": "male", | ||
"address": "sadfsgbhfgtbrg", | ||
"id": 2 | ||
}; | ||
const response = await instance.get('/2', { | ||
headers: { | ||
accept: 'application/json' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.headers['content-type']).toEqual('application/json'); | ||
expect(response.data).toEqual( | ||
user | ||
); | ||
}); | ||
|
||
it('/remove user', async () => { | ||
|
||
const response = await instance.delete('/2', { | ||
headers: { | ||
accept: '*/*' | ||
} | ||
}); | ||
expect(response.status).toEqual(200); | ||
expect(response.data).toEqual("user deleted"); | ||
}); | ||
|
||
it('/get deleted user or not existing user', async () => { | ||
try { | ||
const response = await instance.get('/2', { | ||
headers: { | ||
accept: '*/*' | ||
} | ||
}); | ||
} | ||
catch (ex) { | ||
expect(ex.response.status).toEqual(404); | ||
expect(ex.response.data).toEqual('invalid user id'); | ||
} | ||
}); | ||
|
||
afterAll(() => { | ||
return app.destroy(); | ||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
transform: { | ||
'^.+\\.js?$': 'babel-jest' | ||
}, | ||
testEnvironment: 'node', | ||
testRegex: '.*\\.(test|spec)?\\.(ts|tsx|js)$', | ||
moduleFileExtensions: ['ts', 'js'], | ||
|
||
}; |
Oops, something went wrong.