-
Notifications
You must be signed in to change notification settings - Fork 72
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 #64 from macacajs/test-delegate
test(delegate): test dingtalk integration, pass response to controller
- Loading branch information
Showing
6 changed files
with
62 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"singleQuote": true | ||
} |
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 |
---|---|---|
@@ -1,28 +1,24 @@ | ||
'use strict'; | ||
|
||
const { | ||
Controller, | ||
} = require('egg'); | ||
const { Controller } = require('egg'); | ||
|
||
class DelegateController extends Controller { | ||
|
||
async message() { | ||
const ctx = this.ctx; | ||
const { | ||
webhook, | ||
text, | ||
title, | ||
} = ctx.request.body; | ||
const { webhook, text, title } = ctx.request.body; | ||
|
||
await ctx.helper.sendMarkdown({ | ||
const res = await ctx.helper.sendMarkdown({ | ||
webhook, | ||
title: title || 'title', | ||
text, | ||
}); | ||
|
||
ctx.success({}); | ||
if (res.data) { | ||
ctx.success(res.data); | ||
} else { | ||
ctx.success({}); | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = DelegateController; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ start server: | |
|
||
```bash | ||
npm run dev | ||
# open app at localhost:7001 | ||
``` | ||
|
||
insert seed data: | ||
|
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,40 @@ | ||
'use strict'; | ||
|
||
const { app, assert } = require('egg-mock/bootstrap'); | ||
|
||
describe('test/app/controller/delegate.test.js', () => { | ||
const webhook = { | ||
url: 'https://oapi.dingtalk.com/robot/send?access_token=xxxxx', | ||
}; | ||
const title = 'test title'; | ||
const text = [ 'text1', 'text2' ]; | ||
const responseData = { test: 1 }; | ||
|
||
before(function() { | ||
app.mockContext({ | ||
helper: { | ||
sendMarkdown: async options => { | ||
assert.deepStrictEqual(options.webhook, webhook); | ||
assert.deepStrictEqual(options.title, title); | ||
assert.deepStrictEqual(options.text, text); | ||
return { | ||
data: responseData, | ||
}; | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('POST /api/delegate/message delegate message', async () => { | ||
const { body } = await app | ||
.httpRequest() | ||
.post('/api/delegate/message') | ||
.send({ | ||
webhook, | ||
title, | ||
text, | ||
}); | ||
assert(body.success); | ||
assert.deepStrictEqual(body.data, responseData); | ||
}); | ||
}); |