-
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.
test(delegate): test dingtalk integration, pass response to controller
- Loading branch information
Showing
5 changed files
with
44 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,25 @@ | ||
'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; | ||
console.log(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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const { app, assert } = require('egg-mock/bootstrap'); | ||
|
||
describe('test/app/controller/delegate.test.js', () => { | ||
it('POST /api/delegate/message delegate message', async () => { | ||
const { body } = await app | ||
.httpRequest() | ||
.post('/api/delegate/message') | ||
.send({ | ||
webhook: { | ||
url: 'https://oapi.dingtalk.com/robot/send?access_token=xxxxx', | ||
}, | ||
title: 'title', | ||
text: [ 'text1', 'text2' ], | ||
}); | ||
assert(body.success); | ||
const data = body.data; | ||
// data is the response from DingTalk, something like { errmsg: 'token is not exist', errcode: 300001 } | ||
assert(data); | ||
}); | ||
}); |