forked from mongoosejs/sample-apps
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated tests for discord bot sample app #141
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2efa513
proof of concept for automated tests for discord bot
vkarpov15 c1847b1
test cases for discord bot
vkarpov15 17411b8
undo mistakenly committed changes
vkarpov15 1beca39
run tests on pull request
vkarpov15 391e08e
Merge branch 'main' into vkarpov15/discord-bot-tests
vkarpov15 40da34e
make test.yml workflow consistent with stargate-mongoose
vkarpov15 73e5c7b
bump stargate and json api versions
vkarpov15 ad4d5ca
make ecommerce tests consistent with discord bot tests
vkarpov15 e6f2c8c
add local test env for ecommerce app
vkarpov15 3278ff7
quick fix so sinon stub actually runs
vkarpov15 257f713
add ESLint for netlify-functions-ecommerce and run ESLint with tests
vkarpov15 d6e34af
Merge branch 'main' into vkarpov15/discord-bot-tests
vkarpov15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,2 +1,2 @@ | ||
stargate_version=v2.1.0-ALPHA-6 | ||
json_api_version=v1.0.0-ALPHA-12 | ||
stargate_version=v2.1.0-BETA-2 | ||
json_api_version=v1.0.0-BETA-3 |
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 @@ | ||
JSON_API_URL=http://127.0.0.1:8181/v1/discordbot_test | ||
JSON_API_AUTH_USERNAME=cassandra | ||
JSON_API_AUTH_PASSWORD=cassandra | ||
JSON_API_AUTH_URL=http://localhost:8081/v1/auth |
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,21 @@ | ||
'use strict'; | ||
|
||
const Bot = require('../models/bot'); | ||
const assert = require('assert'); | ||
const { describe, it } = require('mocha'); | ||
const countdocuments = require('../commands/countdocuments'); | ||
const sinon = require('sinon'); | ||
|
||
describe('countdocuments', function() { | ||
it('returns the number of bot documents', async function() { | ||
await Bot.deleteMany({}); | ||
await Bot.create({ name: 'test' }); | ||
|
||
const interaction = { | ||
reply: sinon.stub() | ||
}; | ||
await countdocuments.execute(interaction); | ||
assert.ok(interaction.reply.calledOnce); | ||
assert.deepEqual(interaction.reply.getCalls()[0].args, [1]); | ||
}); | ||
}); |
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,24 @@ | ||
'use strict'; | ||
|
||
const Bot = require('../models/bot'); | ||
const assert = require('assert'); | ||
const { describe, it } = require('mocha'); | ||
const createdocument = require('../commands/createdocument'); | ||
const sinon = require('sinon'); | ||
|
||
describe('createdocument', function() { | ||
it('inserts a new document', async function() { | ||
await Bot.deleteMany({}); | ||
|
||
const interaction = { | ||
reply: sinon.stub() | ||
}; | ||
await createdocument.execute(interaction); | ||
assert.ok(interaction.reply.calledOnce); | ||
assert.deepEqual(interaction.reply.getCalls()[0].args, ['done!']); | ||
|
||
const docs = await Bot.find(); | ||
assert.equal(docs.length, 1); | ||
assert.equal(docs[0].name, 'I am a document'); | ||
}); | ||
}); |
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,17 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const { describe, it } = require('mocha'); | ||
const ping = require('../commands/ping'); | ||
const sinon = require('sinon'); | ||
|
||
describe('ping', function() { | ||
it('replies with "Pong!"', async function() { | ||
const interaction = { | ||
reply: sinon.stub() | ||
}; | ||
await ping.execute(interaction); | ||
assert.ok(interaction.reply.calledOnce); | ||
assert.deepEqual(interaction.reply.getCalls()[0].args, ['Pong!']); | ||
}); | ||
}); |
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,21 @@ | ||
'use strict'; | ||
|
||
require('dotenv').config({ path: `${__dirname}/../.env.test` }); | ||
|
||
const Bot = require('../models/bot'); | ||
const { before } = require('mocha'); | ||
const mongoose = require('../mongoose'); | ||
|
||
const uri = process.env.JSON_API_URL; | ||
const jsonApiConnectOptions = { | ||
username: process.env.JSON_API_AUTH_USERNAME, | ||
password: process.env.JSON_API_AUTH_PASSWORD, | ||
authUrl: process.env.JSON_API_AUTH_URL | ||
}; | ||
|
||
before(async function() { | ||
console.log('Connecting to', uri); | ||
await mongoose.connect(uri, jsonApiConnectOptions); | ||
await Bot.db.dropCollection('bots').catch(() => {}); | ||
await Bot.createCollection(); | ||
}); |
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,14 @@ | ||
#Fill the Local JSON API related details only when NODE_ENV is set to 'jsonapi' | ||
#Local JSON API URL for example: http://127.0.0.1:8181/v1/ecommerce_test where 'ecommerce_test' is the keyspace name | ||
JSON_API_URL=http://127.0.0.1:8181/v1/ecommerce_test | ||
#Auth URL for example: http://127.0.0.1:8081/v1/auth | ||
JSON_API_AUTH_URL=http://127.0.0.1:8081/v1/auth | ||
#Auth username and password | ||
JSON_API_AUTH_USERNAME=cassandra | ||
JSON_API_AUTH_PASSWORD=cassandra | ||
|
||
#Fill in Stripe related details if you want to see Stripe integration. | ||
#Otherwise the sample app will bypass Stripe. | ||
STRIPE_SECRET_KEY=test-key | ||
STRIPE_SUCCESS_URL=http://127.0.0.1:8888/order-confirmation | ||
STRIPE_CANCEL_URL=http://127.0.0.1:8888/cart |
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 @@ | ||
public |
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,14 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: [ | ||
'@masteringjs' | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2020 | ||
}, | ||
env: { | ||
node: true, | ||
es6: 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
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,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
env: { | ||
browser: true | ||
}, | ||
globals: { | ||
Vue: true, | ||
VueRouter: 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,3 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (html, css) => { | ||
appendCSS(css); | ||
return { | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for curiosity, is this test necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit this test isn't exactly testing a very complex code path, but I figure it can be a good starting point for someone looking to write their own tests.