Skip to content

Commit

Permalink
remove unused has()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Mar 18, 2020
1 parent d4de9e2 commit a75605d
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 44 deletions.
11 changes: 1 addition & 10 deletions src/server/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ class AsyncStorage extends StorageAPI.Async {

constructor(args: any = {}) {
super();
const { fetch, setState, has, setMetadata, listGames, remove } = args;
const { fetch, setState, setMetadata, listGames, remove } = args;
this.mocks = {
setState: setState || jest.fn(),
fetch: fetch || jest.fn(() => ({})),
has: has || jest.fn(() => true),
setMetadata: setMetadata || jest.fn(),
listGames: listGames || jest.fn(() => []),
remove: remove || jest.fn(),
Expand All @@ -40,14 +39,6 @@ class AsyncStorage extends StorageAPI.Async {
this.mocks.setState(...args);
}

async getState(...args) {
return this.mocks.getState(...args);
}

async has(...args) {
return this.mocks.has(...args);
}

async setMetadata(...args) {
this.mocks.setMetadata(...args);
}
Expand Down
10 changes: 0 additions & 10 deletions src/server/db/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export abstract class Async {
*/
abstract fetch(gameID: string, opts: FetchOpts): Promise<FetchResult>;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): Promise<boolean>;

/**
* Update the game metadata.
*/
Expand Down Expand Up @@ -91,11 +86,6 @@ export abstract class Sync {
*/
abstract fetch(gameID: string, opts: FetchOpts): FetchResult;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): boolean;

/**
* Update the game metadata.
*/
Expand Down
7 changes: 3 additions & 4 deletions src/server/db/flatfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ describe('FlatFile', () => {
expect(result.state).toEqual({ a: 1 });
expect(result.metadata).toEqual({ metadata: true });

let has = await db.has('gameID');
expect(has).toEqual(true);

// Must return all keys
let keys = await db.listGames();
expect(keys).toEqual(['gameID']);

// Must remove game from DB
await db.remove('gameID');
expect(await db.has('gameID')).toEqual(false);
expect(
await db.fetch('gameID', { metadata: true, state: true, log: true })
).toEqual({});

// Shall not return error
await db.remove('gameID');
Expand Down
9 changes: 3 additions & 6 deletions src/server/db/flatfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ export class FlatFile extends StorageAPI.Async {
return await this.games.setItem(key, metadata);
}

async has(id: string): Promise<boolean> {
var keys = await this.games.keys();
return keys.indexOf(id) > -1;
}

async remove(id: string) {
var keys = await this.games.keys();
if (!(keys.indexOf(id) > -1)) return;
this.games.removeItem(id);
await this.games.removeItem(id);
await this.games.removeItem(LogKey(id));
await this.games.removeItem(MetadataKey(id));
}

async listGames(): Promise<string[]> {
Expand Down
8 changes: 1 addition & 7 deletions src/server/db/inmemory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ describe('InMemory', () => {
expect(state).toEqual(stateEntry);
});

test('has', () => {
// Must return true if game exists
let has = db.has('gameID');
expect(has).toEqual(true);
});

test('listGames', () => {
let keys = db.listGames();
expect(keys).toEqual(['gameID']);
Expand All @@ -54,7 +48,7 @@ describe('InMemory', () => {
test('remove', () => {
// Must remove game from DB
db.remove('gameID');
expect(db.has('gameID')).toEqual(false);
expect(db.fetch('gameID', { state: true })).toEqual({});
// Shall not return error
db.remove('gameID');
});
Expand Down
7 changes: 0 additions & 7 deletions src/server/db/inmemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ export class InMemory extends StorageAPI.Sync {
return result;
}

/**
* Check if a particular game id exists.
*/
has(gameID: string): boolean {
return this.games.has(gameID);
}

/**
* Remove the game state from the in-memory object.
*/
Expand Down

0 comments on commit a75605d

Please sign in to comment.