-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add jest round2 #37
Merged
glagius
merged 4 commits into
hexlet-codebattle:master
from
VladimirAfanasievFS:add_jest_round2
Oct 5, 2020
Merged
Add jest round2 #37
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -12,3 +12,9 @@ lint: | |
|
||
make lint-fix: | ||
npx eslint . --fix | ||
|
||
test: | ||
npx jest | ||
|
||
test-watch: | ||
npx jest --watch |
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,5 @@ | ||
const getRemoveResponse = gameId => ({ | ||
data: JSON.stringify([null, null, 'lobby', 'game:remove', { id: gameId }]), | ||
}); | ||
|
||
export default getRemoveResponse; |
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,36 @@ | ||
const getUpdateResponse = (gameId, state = 'waiting_opponent') => ({ | ||
data: JSON.stringify([null, | ||
null, | ||
'lobby', | ||
'game:upsert', | ||
{ | ||
game: { | ||
id: gameId, | ||
inserted_at: '2020-10-04T22:38:22', | ||
is_bot: false, | ||
level: 'elementary', | ||
players: [{ | ||
id: 2782, | ||
name: 'H9ko', | ||
is_bot: false, | ||
github_id: 57991929, | ||
lang: 'js', | ||
editor_text: 'module.exports = () => {\n\n};', | ||
editor_lang: 'js', | ||
creator: true, | ||
game_result: 'undefined', | ||
check_result: { | ||
asserts: [], asserts_count: 0, output: '', result: '{"status": "info"}', status: 'initial', success_count: 0, | ||
}, | ||
achievements: ['played_ten_games', 'played_fifty_games'], | ||
rating: 1152, | ||
rating_diff: 0, | ||
}], | ||
state, | ||
timeout_seconds: 7200, | ||
type: 'public', | ||
}, | ||
}]), | ||
}); | ||
|
||
export default getUpdateResponse; |
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,159 @@ | ||
export default { | ||
data: JSON.stringify([ | ||
'7', | ||
'7', | ||
'lobby', | ||
'phx_reply', | ||
{ | ||
response: { | ||
active_games: [ | ||
{ | ||
id: 19887, | ||
inserted_at: '2020-09-27T13:30:54', | ||
is_bot: true, | ||
level: 'medium', | ||
players: [ | ||
{ | ||
id: -27, | ||
name: 'HappyQleaner', | ||
is_bot: true, | ||
github_id: 35539033, | ||
lang: 'js', | ||
editor_text: 'module.exports = () => {\n\n};', | ||
editor_lang: 'js', | ||
creator: true, | ||
game_result: 'undefined', | ||
check_result: { | ||
asserts: [], | ||
asserts_count: 0, | ||
output: '', | ||
result: '{"status": "info"}', | ||
status: 'initial', | ||
success_count: 0, | ||
}, | ||
achievements: [ | ||
'played_hundred_games', | ||
'win_games_with?clojure_cpp_csharp_golang_haskell_js_kotlin_php_python_ruby', | ||
], | ||
rating: 1365, | ||
rating_diff: 0, | ||
}, | ||
], | ||
state: 'waiting_opponent', | ||
timeout_seconds: 3600, | ||
type: 'bot', | ||
}, | ||
{ | ||
id: 19923, | ||
inserted_at: '2020-09-28T12:17:11', | ||
is_bot: true, | ||
level: 'hard', | ||
players: [ | ||
{ | ||
id: -18, | ||
name: 'DenisPython', | ||
is_bot: true, | ||
github_id: 35539033, | ||
lang: 'js', | ||
editor_text: 'module.exports = () => {\n\n};', | ||
editor_lang: 'js', | ||
creator: true, | ||
game_result: 'undefined', | ||
check_result: { | ||
asserts: [], | ||
asserts_count: 0, | ||
output: '', | ||
result: '{"status": "info"}', | ||
status: 'initial', | ||
success_count: 0, | ||
}, | ||
achievements: [ | ||
'played_hundred_games', | ||
'win_games_with?cpp_csharp_elixir_golang_haskell_java_js_php_python_ruby_ts', | ||
], | ||
rating: 1344, | ||
rating_diff: 0, | ||
}, | ||
], | ||
state: 'waiting_opponent', | ||
timeout_seconds: 3600, | ||
type: 'bot', | ||
}, | ||
{ | ||
id: 20011, | ||
inserted_at: '2020-09-30T16:15:49', | ||
is_bot: true, | ||
level: 'elementary', | ||
players: [ | ||
{ | ||
id: -9, | ||
name: 'UlaBack', | ||
is_bot: true, | ||
github_id: 35539033, | ||
lang: 'ruby', | ||
editor_text: 'module.exports = () => {\n\n};', | ||
editor_lang: 'ruby', | ||
creator: true, | ||
game_result: 'undefined', | ||
check_result: { | ||
asserts: [], | ||
asserts_count: 0, | ||
output: '', | ||
result: '{"status": "info"}', | ||
status: 'initial', | ||
success_count: 0, | ||
}, | ||
achievements: [ | ||
'played_hundred_games', | ||
'win_games_with?cpp_csharp_elixir_haskell_java_js_php_python_ruby', | ||
], | ||
rating: 1261, | ||
rating_diff: 0, | ||
}, | ||
], | ||
state: 'waiting_opponent', | ||
timeout_seconds: 3600, | ||
type: 'bot', | ||
}, | ||
{ | ||
id: 20013, | ||
inserted_at: '2020-09-30T17:14:20', | ||
is_bot: true, | ||
level: 'easy', | ||
players: [ | ||
{ | ||
id: -5, | ||
name: 'ValyaFront', | ||
is_bot: true, | ||
github_id: 35539033, | ||
lang: 'js', | ||
editor_text: 'module.exports = () => {\n\n};', | ||
editor_lang: 'js', | ||
creator: true, | ||
game_result: 'undefined', | ||
check_result: { | ||
asserts: [], | ||
asserts_count: 0, | ||
output: '', | ||
result: '{"status": "info"}', | ||
status: 'initial', | ||
success_count: 0, | ||
}, | ||
achievements: [ | ||
'played_hundred_games', | ||
'win_games_with?clojure_cpp_elixir_golang_java_js_php_python_ruby', | ||
], | ||
rating: 1287, | ||
rating_diff: 0, | ||
}, | ||
], | ||
state: 'waiting_opponent', | ||
timeout_seconds: 3600, | ||
type: 'bot', | ||
}, | ||
], | ||
}, | ||
status: 'ok', | ||
}, | ||
]), | ||
}; |
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,46 @@ | ||
import browser from 'webextension-polyfill'; | ||
import socketConnect from '../src/background/socket'; | ||
import gameStatuses from '../src/background/models'; | ||
import phxReply4bots from '../__fixtures__/phxReply4bots'; | ||
import getUpdateResponseWithID from '../__fixtures__/getUpdateResponse'; | ||
import getRemoveResponseWithID from '../__fixtures__/getRemoveResponse'; | ||
|
||
describe('socket', () => { | ||
const fakeSocket = {}; | ||
socketConnect(('wss://codebattle.hexlet.io/extension/websocket?vsn=2.0.0'), fakeSocket); | ||
|
||
test('phxReply', () => { | ||
fakeSocket.onmessage(phxReply4bots); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: null, | ||
}); | ||
}); | ||
test('add games->remove games', () => { | ||
fakeSocket.onmessage(getUpdateResponseWithID(1000, gameStatuses.waiting)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: '1', | ||
}); | ||
fakeSocket.onmessage(getUpdateResponseWithID(1001, gameStatuses.waiting)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: '2', | ||
}); | ||
fakeSocket.onmessage(getRemoveResponseWithID(1001)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: '1', | ||
}); | ||
fakeSocket.onmessage(getRemoveResponseWithID(1000)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: null, | ||
}); | ||
}); | ||
test('add game -> changeStatus', () => { | ||
fakeSocket.onmessage(getUpdateResponseWithID(1002, gameStatuses.waiting)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: '1', | ||
}); | ||
fakeSocket.onmessage(getUpdateResponseWithID(1002, gameStatuses.joined)); | ||
expect(browser.browserAction.setBadgeText).toHaveBeenLastCalledWith({ | ||
text: null, | ||
}); | ||
}); | ||
}); |
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.
Если честно, я пока не понял как эта штука сработала.
Ощущение что либо у нас неправильно сделан socketConnect, либо где-то идёт мухлеж с кодом
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.
Ну не мухлеж... Все по заветам хекслета. Это идея из продвинутого тестирования. Сущность сокета по умолчанию устанавливается, и если явно не передать в socketConnect