diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-02 02:49:39 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-02 02:49:39 -0800 |
commit | 438b369d5efdfdf8e7ea3b70540f5e7cf9929e93 (patch) | |
tree | 7a4e86146c79d64e8c8e35db37ea2824eafae07b /server/src/server.test.ts | |
parent | cc3c82a0b2816a4e1601d237a130cf7bae953335 (diff) |
Let\'s try again
Diffstat (limited to 'server/src/server.test.ts')
-rw-r--r-- | server/src/server.test.ts | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/server/src/server.test.ts b/server/src/server.test.ts index b4a308f..2d0efca 100644 --- a/server/src/server.test.ts +++ b/server/src/server.test.ts @@ -11,21 +11,43 @@ import { dbFactory, DatabaseConnection } from '../../client/src' const port = +(process.env.PORT || 5005) const httpPort = port const wsPort = port + 1 +const localHost = 'http://localhost:' describe('Server module', async () => { let db: DatabaseConnection + let cleanup: () => Promise<void> beforeAll(async () => { - await runServer({ + cleanup = await runServer({ httpPort, wsPort, logger: console.log }) - db = dbFactory({ wsPort, httpUrl: `http://localhost:${httpPort}` }) + db = dbFactory({ + wsUrl: `${localHost}${wsPort}`, + httpUrl: `${localHost}${httpPort}` + }) await db.init() }) - test('it should work', async () => { - await db.write('/hello/world', { + afterAll(async () => { + if (cleanup) { + await cleanup() + } + }) + test('it should leave input data unchaged', async () => { + const path = '/hello/world' + const fixture = { my: 'data' + } + await db.write(path, fixture) + const r = await db.read(path) + expect(r).toMatchObject(fixture) + }) + test('it should get data in realtime', () => { + return new Promise(async (resolve, reject) => { + db.subscribe('/hello/world', (data: any) => { + resolve() + }) + await db.write('/hello/world', { data: 5 }) }) }) }) |