Skip to content

Commit

Permalink
feat: rename deprecated storage API methods
Browse files Browse the repository at this point in the history
This renames the class methods `listGames` to `listMatches` and `createGame` to `createMatches` in
line with deprecations introduced in [email protected].

BREAKING CHANGE: Versions of boardgame.io <0.41.1 are no longer supported and other uses that
directly relied on calling `listGames` or `createGame` will need to be updated to use the new method
names.
  • Loading branch information
delucis committed Oct 20, 2020
1 parent 86c86fd commit 42be298
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@types/jest": "^26.0.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"boardgame.io": ">=0.40.0",
"boardgame.io": ">=0.41.1",
"commitizen": "^4.0.4",
"coveralls": "^3.0.11",
"cz-conventional-changelog": "^3.1.0",
Expand All @@ -75,6 +75,6 @@
"firebase-admin": "^9.0.0"
},
"peerDependencies": {
"boardgame.io": ">=0.40 <0.42"
"boardgame.io": ">=0.41.1"
}
}
8 changes: 4 additions & 4 deletions src/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class Firestore extends Async {
// No-op, but required by boardgame.io
}

async createGame(
async createMatch(
gameID: string,
opts: StorageAPI.CreateGameOpts
opts: StorageAPI.CreateMatchOpts
): Promise<void> {
await this.db
.batch()
Expand Down Expand Up @@ -159,10 +159,10 @@ export class Firestore extends Async {
.commit();
}

async listGames({
async listMatches({
gameName,
where = {},
}: StorageAPI.ListGamesOpts = {}): Promise<string[]> {
}: StorageAPI.ListMatchesOpts = {}): Promise<string[]> {
let ref: admin.firestore.Query = this.metadata;

// Filter by updatedAt time if requested.
Expand Down
42 changes: 21 additions & 21 deletions test/bgio-firebase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Firestore', () => {

afterEach(async () => {
// clean database after each test
const ids = await db.listGames();
const ids = await db.listMatches();
await Promise.all(ids.map((id) => db.wipe(id)));
});

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Firestore', () => {
// Create game.
const initialState = ({ G: 'G', ctx: 'ctx' } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
await db.createGame('gameID', { initialState, metadata });
await db.createMatch('gameID', { initialState, metadata });

// Must return created game.
const data = await db.fetch('gameID', {
Expand All @@ -112,7 +112,7 @@ describe('Firestore', () => {
// Create game.
const initialState = ({ G: 'G', ctx: 'ctx' } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
await db.createGame('gameID', { initialState, metadata });
await db.createMatch('gameID', { initialState, metadata });

// Must return no fields.
const data = await db.fetch('gameID', {});
Expand All @@ -126,7 +126,7 @@ describe('Firestore', () => {
// Create game.
const initialState = ({ G: 'G', ctx: 'ctx' } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
await db.createGame('gameID', { initialState, metadata });
await db.createMatch('gameID', { initialState, metadata });

// Metadata should not contain `isGameover` field.
const data = await db.fetch('gameID', { metadata: true });
Expand All @@ -150,7 +150,7 @@ describe('Firestore', () => {
const id = 'B';
const initialState = ({ G: 'G', _stateID: 0 } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
await db.createGame(id, { initialState, metadata });
await db.createMatch(id, { initialState, metadata });

const initialData = await db.fetch(id, { state: true });
expect(initialData.state).toEqual(initialState);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('Firestore', () => {
const id = 'D';
const initialState = ({ G: 'G', _stateID: 0 } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
await db.createGame(id, { initialState, metadata });
await db.createMatch(id, { initialState, metadata });

// Update state, including deltalogs.
const logEntry1 = { turn: 1 } as LogEntry;
Expand All @@ -196,7 +196,7 @@ describe('Firestore', () => {
});
});

describe('#listGames', () => {
describe('#listMatches', () => {
beforeEach(async () => {
await db.setMetadata('gameID_0', {
gameName: 'A',
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Firestore', () => {
});

test('lists all entries', async () => {
const ids = await db.listGames();
const ids = await db.listMatches();
expect(ids).toContain('gameID_0');
expect(ids).toContain('gameID_1');
expect(ids).toContain('gameID_2');
Expand All @@ -238,7 +238,7 @@ describe('Firestore', () => {
});

test('lists entries for specific gameName', async () => {
const ids = await db.listGames({ gameName: 'A' });
const ids = await db.listMatches({ gameName: 'A' });
expect(ids).toContain('gameID_0');
expect(ids).not.toContain('gameID_1');
expect(ids).toContain('gameID_2');
Expand All @@ -248,7 +248,7 @@ describe('Firestore', () => {
});

test('lists entries where game is over', async () => {
const ids = await db.listGames({ where: { isGameover: true } });
const ids = await db.listMatches({ where: { isGameover: true } });
expect(ids).not.toContain('gameID_0');
expect(ids).not.toContain('gameID_1');
expect(ids).toContain('gameID_2');
Expand All @@ -258,7 +258,7 @@ describe('Firestore', () => {
});

test('lists entries where game is not over', async () => {
const ids = await db.listGames({ where: { isGameover: false } });
const ids = await db.listMatches({ where: { isGameover: false } });
expect(ids).toContain('gameID_0');
expect(ids).toContain('gameID_1');
expect(ids).not.toContain('gameID_2');
Expand All @@ -268,15 +268,15 @@ describe('Firestore', () => {
});

test('lists entries where game is over for specific gameName', async () => {
const ids = await db.listGames({
const ids = await db.listMatches({
gameName: 'B',
where: { isGameover: true },
});
expect(ids).toEqual(['gameID_4']);
});

test('lists entries updated before a specific time', async () => {
const ids = await db.listGames({ where: { updatedBefore: 1025 } });
const ids = await db.listMatches({ where: { updatedBefore: 1025 } });
expect(ids).toContain('gameID_0');
expect(ids).toContain('gameID_1');
expect(ids).toContain('gameID_2');
Expand All @@ -286,7 +286,7 @@ describe('Firestore', () => {
});

test('lists entries updated after a specific time', async () => {
const ids = await db.listGames({ where: { updatedAfter: 1025 } });
const ids = await db.listMatches({ where: { updatedAfter: 1025 } });
expect(ids).not.toContain('gameID_0');
expect(ids).not.toContain('gameID_1');
expect(ids).not.toContain('gameID_2');
Expand All @@ -296,7 +296,7 @@ describe('Firestore', () => {
});

test('lists entries updated within a time range', async () => {
const ids = await db.listGames({
const ids = await db.listMatches({
where: { updatedAfter: 1025, updatedBefore: 1035 },
});
expect(ids).not.toContain('gameID_0');
Expand All @@ -308,7 +308,7 @@ describe('Firestore', () => {
});

test('lists entries with multiple filter conditions', async () => {
let ids = await db.listGames({
let ids = await db.listMatches({
gameName: 'A',
where: { updatedAfter: 1020, isGameover: false },
});
Expand All @@ -319,7 +319,7 @@ describe('Firestore', () => {
expect(ids).not.toContain('gameID_4');
expect(ids).toContain('gameID_5');

ids = await db.listGames({
ids = await db.listMatches({
gameName: 'A',
where: { updatedAfter: 1020, isGameover: true },
});
Expand Down Expand Up @@ -372,7 +372,7 @@ describe('Firestore', () => {
});

test('list entries with multiple filter conditions', async () => {
const ids = await db.listGames({
const ids = await db.listMatches({
gameName: 'A',
where: { updatedAfter: 1020, isGameover: false },
});
Expand All @@ -391,11 +391,11 @@ describe('Firestore', () => {
const initialState = ({ G: 'G', ctx: 'ctx' } as unknown) as State;
const metadata = { gameName: 'A' } as Server.MatchData;
// Insert 2 entries
await db.createGame('gameID_6', { initialState, metadata });
await db.createGame('gameID_7', { initialState, metadata });
await db.createMatch('gameID_6', { initialState, metadata });
await db.createMatch('gameID_7', { initialState, metadata });
// Remove 1
await db.wipe('gameID_7');
const games = await db.listGames();
const games = await db.listMatches();
expect(games).toContain('gameID_6');
expect(games).not.toContain('gameID_7');
const data = await db.fetch('gameID_7', {
Expand Down

0 comments on commit 42be298

Please sign in to comment.