-
Notifications
You must be signed in to change notification settings - Fork 9
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 #37 from H9ko/add_jest_round2
Add jest round2
- Loading branch information
Showing
8 changed files
with
7,749 additions
and
3,570 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
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.