Skip to content

Commit fc1ad84

Browse files
authored
Merge pull request #69 from TaloDev/develop
Release 0.6.2
2 parents 3cdddd3 + 96f3b3c commit fc1ad84

File tree

6 files changed

+71
-5
lines changed

6 files changed

+71
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "game-services",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"description": "",
55
"main": "src/index.ts",
66
"scripts": {

src/lib/props/sanitiseProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const sanitiseProps = (props: Prop[], deleteNull = false): Prop[] => {
55

66
if (deleteNull) props = props.filter((prop) => prop.value !== null)
77

8-
return props.map((prop) => new Prop(String(prop.key), prop.value ? String(prop.value) : null))
8+
return props.filter((prop) => Boolean(prop.key)).map((prop) => new Prop(String(prop.key), prop.value ? String(prop.value) : null))
99
}
1010

1111
export default sanitiseProps

src/services/api/player-api.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ export default class PlayerAPIService extends APIService<PlayerService> {
130130
game: key.game
131131
})
132132

133+
if (!player1) req.ctx.throw(404, `Player with alias ${alias1} does not exist`)
134+
133135
const player2 = await em.getRepository(Player).findOne({
134136
aliases: {
135137
id: alias2
136138
},
137139
game: key.game
138140
})
139141

142+
if (!player2) req.ctx.throw(404, `Player with alias ${alias2} does not exist`)
143+
140144
const player2Aliases = await em.getRepository(PlayerAlias).find({
141145
player: {
142146
id: player2.id

src/services/player.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default class PlayerService implements Service {
157157
playerId: player.id,
158158
display: {
159159
'Player': player.id,
160-
'Updated props': props.map((prop) => `${prop.key}: ${prop.value ?? '[deleted]'}`).join(', ')
160+
'Updated props': sanitiseProps(props).map((prop) => `${prop.key}: ${prop.value ?? '[deleted]'}`).join(', ')
161161
}
162162
}
163163
})

tests/services/_api/player-api/merge.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('Player API service - merge', () => {
4949
expect(res.body).toStrictEqual({ message: 'Missing access key scope(s): read:players, write:players' })
5050
})
5151

52-
5352
it('should not merge without the write scope', async () => {
5453
apiKey.scopes = [APIKeyScope.READ_PLAYERS]
5554
await (<EntityManager>app.context.em).flush()
@@ -64,7 +63,6 @@ describe('Player API service - merge', () => {
6463
expect(res.body).toStrictEqual({ message: 'Missing access key scope(s): write:players' })
6564
})
6665

67-
6866
it('should not merge without the read scope', async () => {
6967
apiKey.scopes = [APIKeyScope.WRITE_PLAYERS]
7068
await (<EntityManager>app.context.em).flush()
@@ -183,4 +181,38 @@ describe('Player API service - merge', () => {
183181
}
184182
])
185183
})
184+
185+
it('should not merge players if alias1 does not exist', async () => {
186+
apiKey.scopes = [APIKeyScope.READ_PLAYERS, APIKeyScope.WRITE_PLAYERS]
187+
token = await createToken(apiKey)
188+
189+
const player2 = await new PlayerFactory([apiKey.game]).one()
190+
191+
await (<EntityManager>app.context.em).persistAndFlush(player2)
192+
193+
const res = await request(app.callback())
194+
.post(`${baseUrl}`)
195+
.send({ alias1: 2321, alias2: player2.aliases[0].id })
196+
.auth(token, { type: 'bearer' })
197+
.expect(404)
198+
199+
expect(res.body).toStrictEqual({ message: 'Player with alias 2321 does not exist' })
200+
})
201+
202+
it('should not merge players if alias2 does not exist', async () => {
203+
apiKey.scopes = [APIKeyScope.READ_PLAYERS, APIKeyScope.WRITE_PLAYERS]
204+
token = await createToken(apiKey)
205+
206+
const player1 = await new PlayerFactory([apiKey.game]).one()
207+
208+
await (<EntityManager>app.context.em).persistAndFlush(player1)
209+
210+
const res = await request(app.callback())
211+
.post(`${baseUrl}`)
212+
.send({ alias1: player1.aliases[0].id, alias2: 2456 })
213+
.auth(token, { type: 'bearer' })
214+
.expect(404)
215+
216+
expect(res.body).toStrictEqual({ message: 'Player with alias 2456 does not exist' })
217+
})
186218
})

tests/services/player/patch.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,34 @@ describe('Player service - patch', () => {
207207

208208
expect(res.body).toStrictEqual({ message: 'Demo accounts cannot update player properties' })
209209
})
210+
211+
it('should filter out props with no keys', async () => {
212+
const player = await new PlayerFactory([validGame]).with(() => ({ props: [] })).one()
213+
214+
await (<EntityManager>app.context.em).persistAndFlush(player)
215+
216+
const res = await request(app.callback())
217+
.patch(`${baseUrl}/${player.id}`)
218+
.send({
219+
props: [
220+
{
221+
key: '',
222+
value: ''
223+
},
224+
{
225+
key: 'zonesExplored',
226+
value: '3'
227+
}
228+
]
229+
})
230+
.auth(token, { type: 'bearer' })
231+
.expect(200)
232+
233+
expect(res.body.player.props).toStrictEqual([
234+
{
235+
key: 'zonesExplored',
236+
value: '3'
237+
}
238+
])
239+
})
210240
})

0 commit comments

Comments
 (0)