Skip to content

Commit 89faece

Browse files
jasonharrisonnicolodavis
authored andcommitted
Rename playerCredentials to credentials for /leave endpoint, update src/lobby/connection.js accordingly (#416)
1 parent 25c2263 commit 89faece

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

docs/api/Lobby.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Accepts two parameters, all required:
9898

9999
`playerID`: the ID used by the player in the game (0, 1...).
100100

101-
`playerCredentials`: the authentication token of the player.
101+
`credentials`: the authentication token of the player.
102102

103103
#### Listing all room instances of a given game
104104

src/lobby/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class _LobbyConnectionImpl {
101101
method: 'POST',
102102
body: JSON.stringify({
103103
playerID: player.id,
104-
playerCredentials: this.playerCredentials,
104+
credentials: this.playerCredentials,
105105
}),
106106
headers: { 'Content-Type': 'application/json' },
107107
}

src/server/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const addApiToServer = ({ app, db, games, lobbyConfig }) => {
183183
const gameName = ctx.params.name;
184184
const roomID = ctx.params.id;
185185
const playerID = ctx.request.body.playerID;
186-
const playerCredentials = ctx.request.body.playerCredentials;
186+
const credentials = ctx.request.body.credentials;
187187
const namespacedGameID = getNamespacedGameID(roomID, gameName);
188188
const gameMetadata = await db.get(GameMetadataKey(namespacedGameID));
189189
if (!playerID) {
@@ -196,8 +196,8 @@ export const addApiToServer = ({ app, db, games, lobbyConfig }) => {
196196
if (!gameMetadata.players[playerID]) {
197197
ctx.throw(404, 'Player ' + playerID + ' not found');
198198
}
199-
if (playerCredentials !== gameMetadata.players[playerID].credentials) {
200-
ctx.throw(403, 'Invalid credentials ' + playerCredentials);
199+
if (credentials !== gameMetadata.players[playerID].credentials) {
200+
ctx.throw(403, 'Invalid credentials ' + credentials);
201201
}
202202

203203
delete gameMetadata.players[playerID].name;

src/server/api.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ describe('.createApiServer', () => {
476476
const app = createApiServer({ db, games });
477477
response = await request(app.callback())
478478
.post('/games/foo/1/leave')
479-
.send('playerID=0&playerCredentials=SECRET1');
479+
.send('playerID=0&credentials=SECRET1');
480480
});
481481

482482
test('is successful', async () => {
@@ -522,7 +522,7 @@ describe('.createApiServer', () => {
522522
const app = createApiServer({ db, games });
523523
response = await request(app.callback())
524524
.post('/games/foo/1/leave')
525-
.send('playerID=0&playerCredentials=SECRET1');
525+
.send('playerID=0&credentials=SECRET1');
526526
expect(setSpy).toHaveBeenCalledWith('1');
527527
expect(setSpy).toHaveBeenCalledWith(
528528
expect.stringMatching(':metadata')
@@ -536,7 +536,7 @@ describe('.createApiServer', () => {
536536
const app = createApiServer({ db, games });
537537
response = await request(app.callback())
538538
.post('/games/foo/1/leave')
539-
.send('playerID=2&playerCredentials=SECRET1');
539+
.send('playerID=2&credentials=SECRET1');
540540
expect(response.status).toEqual(404);
541541
});
542542
});
@@ -546,7 +546,7 @@ describe('.createApiServer', () => {
546546
const app = createApiServer({ db, games });
547547
response = await request(app.callback())
548548
.post('/games/foo/1/leave')
549-
.send('playerID=0&playerCredentials=SECRET2');
549+
.send('playerID=0&credentials=SECRET2');
550550
expect(response.status).toEqual(403);
551551
});
552552
});
@@ -555,7 +555,7 @@ describe('.createApiServer', () => {
555555
const app = createApiServer({ db, games });
556556
response = await request(app.callback())
557557
.post('/games/foo/1/leave')
558-
.send('playerCredentials=foo');
558+
.send('credentials=foo');
559559
});
560560

561561
test('throws error 403', async () => {

0 commit comments

Comments
 (0)