-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breakout storage and use DI to inject it properly, attempting to solve …
- Loading branch information
Showing
13 changed files
with
186 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './clickers'; | ||
export * from './storage'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './clickers.mock'; | ||
export * from './storage.mock'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
export class StorageMock { | ||
|
||
public static CLICKER_IDS: Array<string> = ['yy5d8klsj0', 'q20iexxg4a', 'wao2xajl8a']; | ||
|
||
public get(key: string): Promise<{}> { | ||
let rtn: string = null; | ||
|
||
switch (key) { | ||
case 'ids': | ||
rtn = JSON.stringify(StorageMock.CLICKER_IDS); | ||
break; | ||
case StorageMock.CLICKER_IDS[0]: | ||
rtn = `{"id":"${StorageMock.CLICKER_IDS[0]}","name":"test1","clicks":[{"time":1450410168819,"location":"TODO"}]}`; | ||
break; | ||
case StorageMock.CLICKER_IDS[1]: | ||
rtn = `{"id":"${StorageMock.CLICKER_IDS[1]}","name":"test2","clicks":[{"time":1450410168819,"location":"TODO"},{"time":1450410168945,"location":"TODO"}]}`; | ||
break; | ||
case StorageMock.CLICKER_IDS[2]: | ||
rtn = `{"id":"${StorageMock.CLICKER_IDS[2]}","name":"test3", "clicks":[{ "time": 1450410168819, "location": "TODO" }, { "time": 1450410168945, "location": "TODO" }] }`; | ||
break; | ||
default: | ||
rtn = 'SHOULD NOT BE HERE!'; | ||
} | ||
|
||
return new Promise((resolve: Function) => { | ||
resolve(rtn); | ||
}); | ||
} | ||
|
||
public set(key: string, value: string): Promise<{}> { | ||
return new Promise((resolve: Function) => { | ||
resolve({key: key, value: value}); | ||
}); | ||
} | ||
|
||
public remove(key: string): Promise<{}> { | ||
return new Promise((resolve: Function) => { | ||
resolve({key: key}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Storage } from './'; | ||
import { StorageMock } from './mocks'; | ||
|
||
let storage: Storage = null; | ||
|
||
describe('Storage', () => { | ||
|
||
beforeEach(() => { | ||
spyOn(Storage, 'initStorage').and.returnValue(new StorageMock()); | ||
storage = new Storage(); | ||
spyOn(storage['storage'], 'get').and.callThrough(); | ||
spyOn(storage['storage'], 'set').and.callThrough(); | ||
spyOn(storage['storage'], 'remove').and.callThrough(); | ||
}); | ||
|
||
it('initialises', () => { | ||
expect(storage).not.toBeNull(); | ||
}); | ||
|
||
it('gets', () => { | ||
storage.get('dave'); | ||
expect(storage['storage'].get).toHaveBeenCalledWith('dave'); | ||
}); | ||
|
||
it('sets', () => { | ||
storage.set('dave', 'test'); | ||
expect(storage['storage'].set).toHaveBeenCalledWith('dave', 'test'); | ||
}); | ||
|
||
it('removes', () => { | ||
storage.remove('dave'); | ||
expect(storage['storage'].remove).toHaveBeenCalledWith('dave'); | ||
}); | ||
}); |
Oops, something went wrong.