-
Notifications
You must be signed in to change notification settings - Fork 8
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 #66 from osu-cascades/dev
RC v2.0.1
- Loading branch information
Showing
27 changed files
with
306 additions
and
181 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
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,8 @@ | ||
export default { | ||
get: jest.fn().mockResolvedValue({ | ||
data: {} | ||
}), | ||
request: jest.fn().mockResolvedValue({ | ||
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
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
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,52 @@ | ||
import Search from '../../src/commands/search'; | ||
import config from '../../src/config'; | ||
import axiosMock from '../__mocks__/axios'; | ||
import { message as mockMessage, MockedMessage } from '../mocks/discord'; | ||
import { noResults, results } from './../mockData/search'; | ||
|
||
jest.mock('axios'); | ||
jest.mock('../../src/config.ts'); | ||
|
||
let sendMock: MockedMessage; | ||
beforeEach(() => { | ||
sendMock = jest.fn(); | ||
mockMessage.channel.send = sendMock; | ||
mockMessage.reply = sendMock; | ||
config.googleApiKey = 'abc123'; | ||
config.googleSearchEngineId = '12345678910:some-thing'; | ||
}); | ||
|
||
const setupRequiredMessage = 'Setup Required: Configure Google API keys in the environment variables'; | ||
|
||
describe('Search Command', () => { | ||
describe('Environment Variables', () => { | ||
test('Setup message when missing Google API Key ENV Var', async () => { | ||
config.googleApiKey = undefined; | ||
await Search.execute(['Missing Google API Key'], mockMessage); | ||
expect(sendMock).lastCalledWith(setupRequiredMessage); | ||
}); | ||
test('Setup message when missing Google Search Engine ID ENV Var', async () => { | ||
config.googleSearchEngineId = undefined; | ||
await Search.execute(['Missing Google Search Engine ID'], mockMessage); | ||
expect(sendMock).lastCalledWith(setupRequiredMessage); | ||
}); | ||
}); | ||
test('With no results', async () => { | ||
const mockedData = Promise.resolve({ data: noResults }); | ||
axiosMock.get.mockResolvedValueOnce(mockedData); | ||
await Search.execute(['Nothing here'], mockMessage); | ||
expect(sendMock).lastCalledWith('`No results found.`'); | ||
}); | ||
test('With results', async () => { | ||
const mockedData = Promise.resolve({ data: results }); | ||
axiosMock.get.mockResolvedValueOnce(mockedData); | ||
await Search.execute(['dingusy'], mockMessage); | ||
expect(sendMock).lastCalledWith(results.items[0].link); | ||
}); | ||
test('Malformed Response', async () => { | ||
const mockedData = Promise.resolve({ data: {} }); | ||
axiosMock.get.mockResolvedValueOnce(mockedData); | ||
await Search.execute(['NOPE'], mockMessage); | ||
expect(sendMock).lastCalledWith("I'm Sorry Dave, I'm afraid I can't do that..."); | ||
}); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
|
||
export const noResults = { | ||
queries: { | ||
request: [ | ||
{ totalResults: 0 } | ||
] | ||
} | ||
}; | ||
|
||
export const results = { | ||
queries: { | ||
request: [ | ||
{ totalResults: 1 } | ||
] | ||
}, | ||
items: [ | ||
{ link: 'https://www.google.com/'} | ||
] | ||
}; |
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.