Skip to content

Commit bfe0cf1

Browse files
authored
Merge pull request #605 from SibylLab/anotherLogFix
Another log fix
2 parents d0cc0f3 + e74b1e1 commit bfe0cf1

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"core-js": "^3.6.4",
1717
"easytimer.js": "^2.2.3",
18+
"loglevel": "^1.6.8",
1819
"vue": "^2.6.11",
1920
"vue-router": "^3.1.6",
2021
"vuex": "^3.1.3"

src/store/actions.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { bus } from '@/components/shared/Bus'
22
import router from '@/router'
33

4+
// loging framework
5+
const log = require('loglevel');
6+
47
/**
58
* All actions that are taken involving the vuex state.
69
* These actions should be used when combining multiple mutations or
@@ -62,13 +65,16 @@ export default {
6265

6366
let draw = true
6467
if (payload.playType === "DISCARD") {
68+
log.warn({DiscardBy:payload.player.name, card:payload.card.type, value: payload.card.value})
6569
context.commit('discardCard', payload)
6670
} else if (payload.playType === "REDRAW") {
71+
log.warn({RedrawBy:payload.player.name})
6772
context.commit('giveNewHand', payload)
6873
draw = false
6974
} else if (payload.card.isMimic) {
7075
context.dispatch('playMimic', payload)
7176
} else {
77+
log.warn({Player:payload.player.name, card_played:payload.card.type, value: payload.card.value})
7278
context.dispatch(payload.playType, payload)
7379
}
7480

@@ -93,6 +99,10 @@ export default {
9399
let scores = context.getters.getPlayerScores()
94100
for (let scoreInfo of scores) {
95101
if (scoreInfo.score >= context.state.scoreLimit) {
102+
//Winner Info added on log
103+
let winner = context.state.players.find (p => p.id === scoreInfo.playerId)
104+
log.warn({Winner:winner.name, WinnerScores:scoreInfo.score})
105+
96106
bus.$emit('game-over')
97107
context.commit('changeGameState', {newState: 'winner'})
98108
return
@@ -129,6 +139,7 @@ export default {
129139
* Payload same as executeTurn.
130140
*/
131141
playCardOnStack (context, payload) {
142+
log.warn(payload.player.name, payload.card.type, payload.card.value, payload.target.getScore())
132143
context.commit('removeFromHand', payload)
133144
context.commit('addToStack', payload)
134145
},
@@ -147,6 +158,7 @@ export default {
147158
* Payload same as executeTurn.
148159
*/
149160
playSpecialCard (context, payload) {
161+
log.warn(payload.player.name, payload.card.type)
150162
context.commit('addCardEffect', payload)
151163
context.commit('discardCard', payload)
152164
},
@@ -157,9 +169,15 @@ export default {
157169
* Payload same as executeTurn.
158170
*/
159171
groupStacks (context, payload) {
172+
let stackValue= []
173+
for (let stack of payload.target.values()) {
174+
stackValue.push(stack.getScore())
175+
}
176+
160177
context.commit('removeStacks', {stacks: payload.target})
161178
context.commit('newStack', payload)
162179
context.commit('removeFromHand', payload)
180+
log.warn(payload.player.name, payload.card.type, payload.card.value, stackValue)
163181
},
164182

165183
/**

tests/unit/actions.spec.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import actions from '@/store/actions.js'
22

3+
jest.mock('loglevel')
4+
35
function mockValue (value) { return jest.fn(() => {return value}) }
46

57

@@ -41,6 +43,8 @@ describe('vuex actions', () => {
4143
test('play type is DISCARD', () => {
4244
let payload = {
4345
playType: 'DISCARD',
46+
player: {name: 'jeff'},
47+
card: {type: 'GROUP', value: 4}
4448
}
4549
context.state = {gameState: 'game', turnPlays: []}
4650

@@ -70,6 +74,8 @@ describe('vuex actions', () => {
7074
// will not test all the intermediate steps already tested above
7175
let payload = {
7276
playType: 'REDRAW',
77+
player: {name: 'jeff'},
78+
card: {type: 'GROUP', value: 4}
7379
}
7480
context.state = {gameState: 'game', turnPlays: []}
7581

@@ -98,7 +104,8 @@ describe('vuex actions', () => {
98104
// will not test all the intermediate steps already tested above
99105
let payload = {
100106
playType: 'playCardOnStack',
101-
card: {isMimic: false}
107+
player: {name: 'jeff'},
108+
card: {type: 'GROUP', value: 4, isMimic: false}
102109
}
103110
context.state = {gameState: 'game', turnPlays: []}
104111

@@ -148,12 +155,13 @@ describe('vuex actions', () => {
148155
})
149156
test('game is over', () => {
150157
context.getters = {
151-
getPlayerScores: mockValue([ {score: 60}, {score: 80} ])
158+
getPlayerScores: mockValue([ {playerId: 0, score: 60}, {playerId: 1, score: 80} ])
152159
}
153160
context.state = {
154161
scoreLimit: 75,
155162
activeCard: 'card',
156-
activePlayer: {isAi: true}
163+
activePlayer: {isAi: true},
164+
players: [{id: 0}, {id: 1, name: 'jeff'}]
157165
}
158166
actions.endTurn(context)
159167
expect(context.getters.getPlayerScores.mock.calls.length).toEqual(1)
@@ -184,10 +192,15 @@ describe('vuex actions', () => {
184192
// does not check bus.$emit
185193
})
186194
test('playCardOnStack', () => {
187-
actions.playCardOnStack(context, 'payload')
195+
let payload = {
196+
player: {name: 'jeff'},
197+
card: {type: 'REPEAT', value: 3},
198+
target: {getScore: mockValue(10)}
199+
}
200+
actions.playCardOnStack(context, payload)
188201
expect(context.commit.mock.calls.length).toEqual(2)
189-
expect(context.commit.mock.calls[0]).toEqual([ 'removeFromHand', 'payload' ])
190-
expect(context.commit.mock.calls[1]).toEqual([ 'addToStack', 'payload' ])
202+
expect(context.commit.mock.calls[0]).toEqual([ 'removeFromHand', payload ])
203+
expect(context.commit.mock.calls[1]).toEqual([ 'addToStack', payload ])
191204
})
192205
test('startNewStack', () => {
193206
actions.startNewStack(context, 'payload')
@@ -196,13 +209,24 @@ describe('vuex actions', () => {
196209
expect(context.commit.mock.calls[1]).toEqual([ 'newStack', 'payload' ])
197210
})
198211
test('playSpecialCard', () => {
199-
actions.playSpecialCard(context, 'payload')
212+
let payload = {
213+
player: {name: 'jeff'},
214+
card: {type: 'RANSOM'},
215+
target: {name: 'phil'}
216+
}
217+
actions.playSpecialCard(context, payload)
200218
expect(context.commit.mock.calls.length).toEqual(2)
201-
expect(context.commit.mock.calls[0]).toEqual([ 'addCardEffect', 'payload' ])
202-
expect(context.commit.mock.calls[1]).toEqual([ 'discardCard', 'payload' ])
219+
expect(context.commit.mock.calls[0]).toEqual([ 'addCardEffect', payload ])
220+
expect(context.commit.mock.calls[1]).toEqual([ 'discardCard', payload ])
203221
})
204222
test('groupStacks', () => {
205-
let payload = {target: 'stacks'}
223+
let payload = {
224+
target: new Set([
225+
{getScore: mockValue(2)}, {getScore: mockValue(2)}
226+
]),
227+
card: {type: 'GROUP', value: 4},
228+
player: {name: 'jeff'},
229+
}
206230
actions.groupStacks(context, payload)
207231
expect(context.commit.mock.calls.length).toEqual(3)
208232
expect(context.commit.mock.calls[0]).toEqual([ 'removeStacks', {stacks: payload.target} ])

0 commit comments

Comments
 (0)