Skip to content

Commit

Permalink
Rename playerCredentials to credentials for /leave endpoint, update s…
Browse files Browse the repository at this point in the history
…rc/lobby/connection.js accordingly (#416)
  • Loading branch information
jasonharrison authored and nicolodavis committed Jun 6, 2019
1 parent 25c2263 commit 89faece
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/api/Lobby.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Accepts two parameters, all required:

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

`playerCredentials`: the authentication token of the player.
`credentials`: the authentication token of the player.

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

Expand Down
2 changes: 1 addition & 1 deletion src/lobby/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class _LobbyConnectionImpl {
method: 'POST',
body: JSON.stringify({
playerID: player.id,
playerCredentials: this.playerCredentials,
credentials: this.playerCredentials,
}),
headers: { 'Content-Type': 'application/json' },
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const addApiToServer = ({ app, db, games, lobbyConfig }) => {
const gameName = ctx.params.name;
const roomID = ctx.params.id;
const playerID = ctx.request.body.playerID;
const playerCredentials = ctx.request.body.playerCredentials;
const credentials = ctx.request.body.credentials;
const namespacedGameID = getNamespacedGameID(roomID, gameName);
const gameMetadata = await db.get(GameMetadataKey(namespacedGameID));
if (!playerID) {
Expand All @@ -196,8 +196,8 @@ export const addApiToServer = ({ app, db, games, lobbyConfig }) => {
if (!gameMetadata.players[playerID]) {
ctx.throw(404, 'Player ' + playerID + ' not found');
}
if (playerCredentials !== gameMetadata.players[playerID].credentials) {
ctx.throw(403, 'Invalid credentials ' + playerCredentials);
if (credentials !== gameMetadata.players[playerID].credentials) {
ctx.throw(403, 'Invalid credentials ' + credentials);
}

delete gameMetadata.players[playerID].name;
Expand Down
10 changes: 5 additions & 5 deletions src/server/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ describe('.createApiServer', () => {
const app = createApiServer({ db, games });
response = await request(app.callback())
.post('/games/foo/1/leave')
.send('playerID=0&playerCredentials=SECRET1');
.send('playerID=0&credentials=SECRET1');
});

test('is successful', async () => {
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('.createApiServer', () => {
const app = createApiServer({ db, games });
response = await request(app.callback())
.post('/games/foo/1/leave')
.send('playerID=0&playerCredentials=SECRET1');
.send('playerID=0&credentials=SECRET1');
expect(setSpy).toHaveBeenCalledWith('1');
expect(setSpy).toHaveBeenCalledWith(
expect.stringMatching(':metadata')
Expand All @@ -536,7 +536,7 @@ describe('.createApiServer', () => {
const app = createApiServer({ db, games });
response = await request(app.callback())
.post('/games/foo/1/leave')
.send('playerID=2&playerCredentials=SECRET1');
.send('playerID=2&credentials=SECRET1');
expect(response.status).toEqual(404);
});
});
Expand All @@ -546,7 +546,7 @@ describe('.createApiServer', () => {
const app = createApiServer({ db, games });
response = await request(app.callback())
.post('/games/foo/1/leave')
.send('playerID=0&playerCredentials=SECRET2');
.send('playerID=0&credentials=SECRET2');
expect(response.status).toEqual(403);
});
});
Expand All @@ -555,7 +555,7 @@ describe('.createApiServer', () => {
const app = createApiServer({ db, games });
response = await request(app.callback())
.post('/games/foo/1/leave')
.send('playerCredentials=foo');
.send('credentials=foo');
});

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

0 comments on commit 89faece

Please sign in to comment.