Documentation around creating test JSON
chiefy opened this issue · 6 comments
I'm kind of new to API gateway, but I am having trouble running
claudia test-lambda --event ./my-test.json
{
"context": {
"method": "POST",
"path": "/slack/slash-command",
"sourceIp": "test-invoke-source-ip",
"accountId": "00000000000000",
"apiKey": "test-invoke-api-key",
"authorizerPrincipalId": "",
"caller": "00000000000000",
"cognitoAuthenticationProvider": "",
"cognitoAuthenticationType": "",
"cognitoIdentityId": "",
"cognitoIdentityPoolId": "",
"stage": "test-invoke-stage",
"user": "00000000000000",
"userAgent": "Apache-HttpClient/4.3.4 (java 1.5)",
"userArn": "arn:aws:iam::00000000000000:root"
},
"v": "2",
"body": {
"text": "goonies"
},
"headers": {
"token": "zeJd9jNdslwd933jfnosd0a"
},
"queryString": {},
"env": {
"lambdaVersion": "latest"
},
"pathParams": {}
}
Output:
{
"StatusCode": 200,
"FunctionError": "Handled",
"Payload": "{\"errorMessage\":\"Cannot read property 'token' of undefined\",\"errorType\":\"TypeError\",\"stackTrace\":[\"/var/task/node_modules/claudia-bot-builder/lib/slack/setup.js:14:21\",\"ApiBuilder.self.router (/var/task/node_modules/claudia-bot-builder/node_modules/claudia-api-builder/src/api-builder.js:98:15)\"]}"
}
I have run claudia update --configure-slack-slash-command
and updated it with the slack API token, so I am not exactly sure where I need to provide the token in my test JSON?
Hi @chiefy,
I never tried to run it that way, but you should be able to add slackToken
to env
object.
So, something like this:
"env": {
"lambdaVersion": "latest",
"slackToken": "YourSlackToken"
}
@stojanovic thanks, but I still get the same error. Just trying to figure out a good way to test locally, is there a best-practice for that, I didn't see anything in the examples / docs?
@chiefy I don't test it locally, I do test my code with jasmine or tape, but not the full lambda.
You can test the bot builder itself the same way we did in specs.
Why would you test the full setup locally? Is it easier for you that way?
The problem for full local test for me is that it takes more time to setup everything and I personally don't think it gives much value.
I have a test Slack for bots and apps. Not a perfect solution, but I can see how it really works before exposing it to everyone in the team.
cc. @gojko in case he has some idea how to do that.
PS. Let us know what are you building if you start using Bot builder for something :)
@stojanovic I am just messing around, trying to build a simple slash command for slack - trying to debug what's going on as I am getting a 200
with empty response.
Strange, if you can share the code I think I can help.
@stojanovic I created a new issue #12 as I am having this issue with even the simplest of examples. I will close this one out.