databaseWebSocket.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict'
  2. import test from 'ava'
  3. import WebSocket from 'ws'
  4. import request from 'supertest'
  5. import { json, getTestServer } from './_test_functions'
  6. import DataController from '../../server/database/controllers/Data'
  7. // Database testing
  8. // Before all tests, connect to the database
  9. test.beforeEach(t => getTestServer(t, { database: true, webSocket: true }))
  10. test('Check database is working', async t => {
  11. await request(t.context.server)
  12. const testData = { test_database: 'add', test_database_obj: { msg: 'Hello world' } }
  13. const doc = await DataController.add(testData)
  14. t.deepEqual(doc.data, testData, json(doc))
  15. const findDoc = await DataController.find(doc.id)
  16. t.deepEqual(findDoc.data, testData, json(findDoc))
  17. testData.test_database = 'updated'
  18. const updateTo = { newObject: 'test', newProperties: { test: true } }
  19. const docUpdated = await DataController.update(doc.id, updateTo)
  20. t.deepEqual(docUpdated.data, updateTo, json(docUpdated))
  21. t.notThrowsAsync(await DataController.del(doc.id))
  22. })