From 5962facc2dad125832fd6f7fe6a36e57423741b9 Mon Sep 17 00:00:00 2001 From: GarlicB Date: Mon, 20 Nov 2017 02:29:27 +0900 Subject: [PATCH 1/2] Implement skeleton codes in server/push --- server/base/application.ts | 2 ++ server/push/push.router.ts | 67 ++++++++++++++++++++++++++++++++++++++ server/push/push.test.ts | 37 +++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 server/push/push.router.ts create mode 100644 server/push/push.test.ts diff --git a/server/base/application.ts b/server/base/application.ts index 7feadc65..5bd769ed 100644 --- a/server/base/application.ts +++ b/server/base/application.ts @@ -29,6 +29,7 @@ export class Application { this.app.use(bodyParser.json()); this.app.use(bodyParser.urlencoded({ extended: true })); await import('../example/example.router'); + await import('../push/push.router'); this.app.listen(8090); } @@ -37,6 +38,7 @@ export class Application { this.app.use(bodyParser.json()); this.app.use(bodyParser.urlencoded({ extended: true })); await import('../example/example.router'); + await import('../push/push.router'); return this.app; } diff --git a/server/push/push.router.ts b/server/push/push.router.ts new file mode 100644 index 00000000..9b37289f --- /dev/null +++ b/server/push/push.router.ts @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 The Absolute Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as express from 'express'; +import { Application } from 'server/base/application'; + +/** + * PushRouter + */ +@Application.ROUTE('/push/register') +export class Register { + public post(request: express.Request, response: express.Response): void { + if (request.body) { + if (request.body.param === 'register') { + response.sendStatus(200); + } else { + response.sendStatus(400); + } + } else { + response.sendStatus(501); + } + } +} + +@Application.ROUTE('/push/unregister') +export class Unregister { + public post(request: express.Request, response: express.Response): void { + if (request.body) { + if (request.body.param === 'unregister') { + response.sendStatus(200); + } else { + response.sendStatus(400); + } + } else { + response.sendStatus(501); + } + } +} + + +@Application.ROUTE('/push/send') +export class Send { + public post(request: express.Request, response: express.Response): void { + if (request.body) { + if (request.body.param === 'send') { + response.sendStatus(200); + } else { + response.sendStatus(400); + } + } else { + response.sendStatus(501); + } + } +} diff --git a/server/push/push.test.ts b/server/push/push.test.ts new file mode 100644 index 00000000..979d3b37 --- /dev/null +++ b/server/push/push.test.ts @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2017 The Absolute Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {} from 'jest'; +import {Application} from 'server/base/application'; +import * as supertest from 'supertest'; + +test('POST x-www-form-urlencoded', async() => { + const request: {} = supertest(await Application.START_FOR_TESTING()); + const response: {} = await request.post('/push/register').set('Content-Type', 'application/x-www-form-urlencoded').send('param=register'); + expect(response.statusCode).toBe(200); +}); + +test('POST x-www-form-urlencoded', async() => { + const request: {} = supertest(await Application.START_FOR_TESTING()); + const response: {} = await request.post('/push/unregister').set('Content-Type', 'application/x-www-form-urlencoded').send('param=unregister'); + expect(response.statusCode).toBe(200); +}); + +test('POST x-www-form-urlencoded', async() => { + const request: {} = supertest(await Application.START_FOR_TESTING()); + const response: {} = await request.post('/push/send').set('Content-Type', 'application/x-www-form-urlencoded').send('param=send'); + expect(response.statusCode).toBe(200); +}); From 8471d78a7a0a45685dcaa0a612a45a74adbfa577 Mon Sep 17 00:00:00 2001 From: GarlicB Date: Mon, 20 Nov 2017 15:27:19 +0900 Subject: [PATCH 2/2] Fix lint err --- server/push/push.router.ts | 1 - server/push/push.test.ts | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/push/push.router.ts b/server/push/push.router.ts index 9b37289f..0c9a77bf 100644 --- a/server/push/push.router.ts +++ b/server/push/push.router.ts @@ -50,7 +50,6 @@ export class Unregister { } } - @Application.ROUTE('/push/send') export class Send { public post(request: express.Request, response: express.Response): void { diff --git a/server/push/push.test.ts b/server/push/push.test.ts index 979d3b37..d892edbb 100644 --- a/server/push/push.test.ts +++ b/server/push/push.test.ts @@ -14,24 +14,27 @@ * limitations under the License. */ -import {} from 'jest'; -import {Application} from 'server/base/application'; +import { } from 'jest'; +import { Application } from 'server/base/application'; import * as supertest from 'supertest'; -test('POST x-www-form-urlencoded', async() => { +test('POST x-www-form-urlencoded', async () => { const request: {} = supertest(await Application.START_FOR_TESTING()); - const response: {} = await request.post('/push/register').set('Content-Type', 'application/x-www-form-urlencoded').send('param=register'); + const response: {} = await request.post('/push/register').set + ('Content-Type', 'application/x-www-form-urlencoded').send('param=register'); expect(response.statusCode).toBe(200); }); -test('POST x-www-form-urlencoded', async() => { +test('POST x-www-form-urlencoded', async () => { const request: {} = supertest(await Application.START_FOR_TESTING()); - const response: {} = await request.post('/push/unregister').set('Content-Type', 'application/x-www-form-urlencoded').send('param=unregister'); + const response: {} = await request.post('/push/unregister').set + ('Content-Type', 'application/x-www-form-urlencoded').send('param=unregister'); expect(response.statusCode).toBe(200); }); -test('POST x-www-form-urlencoded', async() => { +test('POST x-www-form-urlencoded', async () => { const request: {} = supertest(await Application.START_FOR_TESTING()); - const response: {} = await request.post('/push/send').set('Content-Type', 'application/x-www-form-urlencoded').send('param=send'); + const response: {} = await request.post('/push/send').set + ('Content-Type', 'application/x-www-form-urlencoded').send('param=send'); expect(response.statusCode).toBe(200); });