3 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
4 var assert = require('assert');
5 var roomMetaService = require('../lib/room-meta-service');
7 describe('room-meta-service #slow', function() {
8 var fixture = fixtureLoader.setupEach({
14 welcomeMessage: 'hello'
21 it('should handle missing metadata', function() {
22 return roomMetaService
23 .findMetaByTroupeId(fixture.troupe1.id, ['welcomeMessage'])
24 .then(function(result) {
25 assert.deepEqual(result, {});
29 it('should upsert and retrieve a record', function() {
30 var welcomeMessage = {
35 return roomMetaService
36 .upsertMetaKey(fixture.troupe2.id, 'welcomeMessage', welcomeMessage)
38 return roomMetaService.findMetaByTroupeId(fixture.troupe2.id, ['welcomeMessage']);
40 .then(function(meta) {
41 assert.deepEqual(meta, { welcomeMessage });
42 // Make sure one meta doesnt override the other, which was happening before
43 return roomMetaService.findMetaByTroupeId(fixture.troupe1.id, ['welcomeMessage']);
45 .then(function(result) {
46 assert.deepEqual(result, {});
50 it('should be able to retrieve keys', async () => {
51 const result = await roomMetaService.findMetaByTroupeId(fixture.troupe2.id, ['welcomeMessage']);
53 assert.deepStrictEqual(result, {
54 welcomeMessage: { text: 'hello' }
58 it('should retrieve metadata for multiple troupes', async () => {
59 const result = await roomMetaService.findMetaByTroupeIds([
64 // converting ids to strings fort easy deep equal comparison
65 const stringIdResult = result.map(meta => ({ ...meta, troupeId: meta.troupeId.toString() }));
67 assert.deepStrictEqual(stringIdResult, [
69 troupeId: fixture.troupe2.id,
70 welcomeMessage: { text: 'hello' }
73 troupeId: fixture.troupe3.id