diff --git a/src/persistence/MCWSPersistenceProvider.js b/src/persistence/MCWSPersistenceProvider.js index 7c3835e..c7207ad 100644 --- a/src/persistence/MCWSPersistenceProvider.js +++ b/src/persistence/MCWSPersistenceProvider.js @@ -78,7 +78,7 @@ export default class MCWSPersistenceProvider extends BaseMCWSPersistenceProvider } catch (error) { console.warn('MCWSPersistneceProvider:update', error); - return; + return false; } } diff --git a/src/persistence/test/MCWSNamespaceModelProviderSpec.js b/src/persistence/test/MCWSNamespaceModelProviderSpec.js index 4b6640a..ff29857 100644 --- a/src/persistence/test/MCWSNamespaceModelProviderSpec.js +++ b/src/persistence/test/MCWSNamespaceModelProviderSpec.js @@ -1,138 +1,246 @@ -/*global define,describe,beforeEach,jasmine,Promise,it,expect*/ -define([ - // '../src/MCWSNamespaceModelProvider' -], function ( - // MCWSNamespaceModelProvider -) { - 'use strict'; - - xdescribe('MCWSNamespaceModelProvider', function () { - var namespaceService, + +import MCWSUserContainerProvider from '../MCWSUserContainerProvider'; +import MCWSPersistenceProvider from '../MCWSPersistenceProvider'; +import mcws from 'services/mcws/mcws'; + +describe('MCWS Providers', () => { + let openmct; + let someNamespace; + let anotherNamespace; + let personalContainerNamespace; + let personalNamespace; + let namespaces; + let userContainerProvider; + let persistenceProvider; + + beforeEach(() => { + openmct = { + user: { + getCurrentUser: () => Promise.resolve({ id: 'myUser' }) + } + }; + + someNamespace = { + id: 'some-namespace:root', + key: 'some-namespace', + name: 'Some Namespace', + url: '/some/namespace/url' + }; + anotherNamespace = { + id: 'another-namespace:root', + key: 'another-namespace', + name: 'Another Namespace', + url: '/another/namespace/url', + location: 'some-namespace:root' + }; + personalContainerNamespace = { + id: 'personal', + key: 'personal', + name: 'personal', + url: '/some/personal/namespace', + containsNamespaces: true, + childTemplate: { + id: 'personal-{username}:root', + key: 'personal-{username}', + name: '{username}', + url: '/some/personal/namespace/{username}' + } + }; + personalNamespace = { + id: 'personal-myUser:root', + key: 'personal-myUser', + name: 'myUser', + url: '/some/personal/namespace/myUser', + location: 'personal' + }; + + namespaces = [ someNamespace, anotherNamespace, personalContainerNamespace, - personalNamespace, - namespaces, - provider; - - beforeEach(function () { - namespaceService = jasmine.createSpyObj( - 'namespaceService', - [ - 'getPersistenceNamespaces', - 'getContainedNamespaces' - ] + personalNamespace + ]; + + const roots = [personalContainerNamespace]; + userContainerProvider = new MCWSUserContainerProvider(openmct, roots); + persistenceProvider = new MCWSPersistenceProvider(openmct, roots); + + // Mock mcws service calls + spyOn(userContainerProvider, 'getPersistenceNamespaces') + .and.returnValue(Promise.resolve(namespaces)); + spyOn(userContainerProvider, 'getContainedNamespaces') + .and.callFake((namespace) => { + if (namespace.id === 'personal') { + return Promise.resolve([personalNamespace]); + } + return Promise.resolve([]); + }); + }); + + describe('MCWSUserContainerProvider', () => { + it('gets container model with contained namespaces', async () => { + const identifier = { + namespace: 'personal', + key: 'container' + }; + const model = await userContainerProvider.get(identifier); + + expect(model.type).toBe('folder'); + expect(model.composition).toEqual([{ key: 'root', namespace: 'personal-myUser' }]); + expect(model.location).toBe('ROOT'); + }); + }); + + describe('MCWSPersistenceProvider', () => { + let mcwsNamespace; + + beforeEach(() => { + // Mock mcws namespace operations + const fileOps = { + read: () => Promise.resolve({ + json: () => Promise.resolve({ + type: 'folder', + name: 'Test Object' + }) + }), + create: jasmine.createSpy('create').and.returnValue(Promise.resolve(true)), + replace: jasmine.createSpy('replace').and.returnValue(Promise.resolve(true)) + }; + mcwsNamespace = { + opaqueFile: () => fileOps + }; + + spyOn(persistenceProvider, 'getPersistenceNamespaces') + .and.returnValue(Promise.resolve(namespaces)); + // Mock the private getNamespace method through the mcws import + spyOn(mcws, 'namespace').and.returnValue(mcwsNamespace); + }); + + it('gets persisted objects', async () => { + const identifier = { + namespace: 'personal-myUser', + key: 'some-object' + }; + const result = await persistenceProvider.get(identifier); + + expect(result).toBeDefined(); + expect(result.type).toBe('folder'); + expect(result.name).toBe('Test Object'); + expect(result.identifier).toEqual(identifier); + }); + + it('handles abort signal when getting objects', async () => { + const identifier = { + namespace: 'personal-myUser', + key: 'some-object' + }; + const abortSignal = new AbortController().signal; + + await persistenceProvider.get(identifier, abortSignal); + + expect(mcws.namespace).toHaveBeenCalledWith( + jasmine.any(String), + { signal: abortSignal } ); + }); - someNamespace = { - id: 'some-namespace:root', - key: 'some-namespace', - name: 'Some Namespace', - url: '/some/namespace/url' + it('creates new objects', async () => { + const domainObject = { + identifier: { + namespace: 'some-namespace', + key: 'new-object' + }, + type: 'folder', + name: 'New Folder' }; - anotherNamespace = { - id: 'another-namespace:root', - key: 'another-namespace', - name: 'Another Namespace', - url: '/another/namespace/url', - location: 'some-namespace:root' + + const success = await persistenceProvider.create(domainObject); + const expectedModel = { + type: 'folder', + name: 'New Folder' }; - personalContainerNamespace = { - id: 'personal', - key: 'personal', - name: 'personal', - url: '/some/personal/namespace' + + expect(success).toBe(true); + expect(mcwsNamespace.opaqueFile('new-object').create) + .toHaveBeenCalledWith(expectedModel); + }); + + it('updates existing objects', async () => { + const domainObject = { + identifier: { + namespace: 'some-namespace', + key: 'existing-object' + }, + type: 'folder', + name: 'Updated Folder' }; - personalNamespace = { - id: 'personal-myUser:root', - key: 'personal-myUser}', - name: 'myUser', - url: '/some/personal/namespace/myUser', - location: 'personal' + + const success = await persistenceProvider.update(domainObject); + const expectedModel = { + type: 'folder', + name: 'Updated Folder' }; - namespaces = [ - someNamespace, - anotherNamespace, - personalContainerNamespace, - personalNamespace - ]; + expect(success).toBe(true); + expect(mcwsNamespace.opaqueFile('existing-object').replace) + .toHaveBeenCalledWith(expectedModel); + }); - namespaceService - .getPersistenceNamespaces - .and.returnValue(Promise.resolve(namespaces)); + it('handles errors during get operation', async () => { + const errorNamespace = { + opaqueFile: () => ({ + read: () => Promise.reject(new Error('Network Error')) + }) + }; + mcws.namespace.and.returnValue(errorNamespace); - namespaceService - .getContainedNamespaces - .and.callFake(function (namespace) { - if (namespace.id === 'personal') { - return Promise.resolve([personalNamespace]); - } - return Promise.resolve([]); - }); + const identifier = { + namespace: 'personal-myUser', + key: 'error-object' + }; + const result = await persistenceProvider.get(identifier); - provider = new MCWSNamespaceModelProvider(namespaceService); + expect(result).toBeUndefined(); }); - describe('getModels', function () { - var someNamespaceModel, - anotherNamespaceModel, - personalContainerNamespaceModel, - personalNamespaceModel, - allNamespaceModels; - - beforeEach(function (done) { - provider - .getModels([ - 'some-namespace:root', - 'another-namespace:root', - 'personal', - 'personal-myUser:root' - ]) - .then(function (models) { - someNamespaceModel = models['some-namespace:root']; - anotherNamespaceModel = - models['another-namespace:root']; - personalContainerNamespaceModel = models.personal; - personalNamespaceModel = models['personal-myUser:root']; - allNamespaceModels = [ - someNamespaceModel, - anotherNamespaceModel, - personalContainerNamespaceModel, - personalNamespaceModel - ]; - }) - .then(done); - }); + it('handles errors during create operation', async () => { + const errorNamespace = { + opaqueFile: () => ({ + create: () => Promise.reject(new Error('Creation Error')) + }) + }; + mcws.namespace.and.returnValue(errorNamespace); - it('sets type to folder', function () { - allNamespaceModels.forEach(function (namespaceModel) { - expect(namespaceModel.type).toBe('folder'); - }); - }); + const domainObject = { + identifier: { + namespace: 'personal-myUser', + key: 'error-object' + }, + type: 'folder' + }; + const success = await persistenceProvider.create(domainObject); - it('uses location specified in namespace definition', function () { - expect(anotherNamespaceModel.location) - .toBe('some-namespace:root'); - expect(personalNamespaceModel.location) - .toBe('personal'); - }); + expect(success).toBe(false); + }); - it('sets default location if not specified', function () { - expect(someNamespaceModel.location).toBe('ROOT'); - expect(personalContainerNamespaceModel.location).toBe('ROOT'); - }); + it('handles errors during update operation', async () => { + const errorNamespace = { + opaqueFile: () => ({ + replace: () => Promise.reject(new Error('Update Error')) + }) + }; + mcws.namespace.and.returnValue(errorNamespace); - it('sets composition', function () { - expect(someNamespaceModel.composition) - .toEqual(jasmine.any(Array)); - expect(anotherNamespaceModel.composition) - .toEqual(jasmine.any(Array)); - expect(personalContainerNamespaceModel.composition) - .toEqual(['personal-myUser:root']); - expect(personalNamespaceModel.composition) - .toEqual(jasmine.any(Array)); - }); + const domainObject = { + identifier: { + namespace: 'personal-myUser', + key: 'error-object' + }, + type: 'folder' + }; + const success = await persistenceProvider.update(domainObject); + + expect(success).toBe(false); }); }); }); diff --git a/src/persistence/test/MCWSNamespaceServiceSpec.js b/src/persistence/test/MCWSNamespaceServiceSpec.js index dae5794..70aa872 100644 --- a/src/persistence/test/MCWSNamespaceServiceSpec.js +++ b/src/persistence/test/MCWSNamespaceServiceSpec.js @@ -1,382 +1,356 @@ -/*global define,describe,beforeEach,jasmine,Promise,it,expect*/ - -define([ - // '../src/MCWSNamespaceService', - // 'services/mcws/mcws' -], function ( - // MCWSNamespaceService, - // mcwsDefault -) { - 'use strict'; - - // const mcws = mcwsDefault.default; - - xdescribe('MCWSNamespaceService', function () { - var $window, - namespaceMIOs, - mockUserAPI, - mockOpenmct, - sharedRootDefinition, - inaccessibleSharedRootDefinition, - missingSharedRootDefinition, - sharedRootDefinitions, - containerRootDefinition, - missingContainerRootDefinition, - inaccessibleContainerRootDefinition, - containerRootDefinitions, - namespaceService; - - beforeEach(function () { - $window = { - location: { - pathname: '/mcws/clients/vista/' - } - }; +import MCWSPersistenceProvider from '../MCWSPersistenceProvider'; +import MCWSUserContainerProvider from '../MCWSUserContainerProvider'; +import mcws from 'services/mcws/mcws'; + +describe('MCWSNamespaceService', () => { + let namespaceMIOs; + let mockUserAPI; + let mockOpenmct; + let sharedRootDefinition; + let inaccessibleSharedRootDefinition; + let missingSharedRootDefinition; + let sharedRootDefinitions; + let containerRootDefinition; + let missingContainerRootDefinition; + let inaccessibleContainerRootDefinition; + let containerRootDefinitions; + let mcwsPersistenceProvider; + let mcwsUserContainerProvider; + + beforeEach(() => { + namespaceMIOs = {}; + + spyOn(mcws, 'namespace'); + + mcws.namespace.and.callFake((namespaceUrl) => { + let namespace = namespaceMIOs[namespaceUrl]; + + if (!namespace) { + namespace = namespaceMIOs[namespaceUrl] = + jasmine.createSpyObj( + `namespace:${namespaceUrl}`, + ['read', 'create'] + ); - namespaceMIOs = {}; - - spyOn(mcws, 'namespace'); - - mcws.namespace.and.callFake(function (namespaceUrl) { - var namespace = namespaceMIOs[namespaceUrl]; - - if (!namespace) { - namespace = namespaceMIOs[namespaceUrl] = - jasmine.createSpyObj( - 'namespace:' + namespaceUrl, - ['read', 'create'] - ); - - namespace.created = false; - - namespace.create.and.callFake(function () { - return Promise.resolve() - .then(function () { - namespace.created = true; - return []; - }); - }); - - namespace.read.and.callFake(function () { - if (namespaceUrl.indexOf('missing') !== -1 && - !namespace.created) { - return Promise.reject({ - status: 404 - }); - } - if (namespaceUrl.indexOf('inaccessible') !== -1) { - return Promise.reject({}); - } - return Promise.resolve([]); - }); - } + namespace.created = false; - return namespace; - }); + namespace.create.and.callFake(() => { + return Promise.resolve() + .then(() => { + namespace.created = true; + return []; + }); + }); - mockUserAPI = jasmine.createSpyObj('userAPI', [ - 'getCurrentUser' - ]); + namespace.read.and.callFake(() => { + if (namespaceUrl.includes('missing') && !namespace.created) { + return Promise.reject({ status: 404 }); + } + if (namespaceUrl.includes('inaccessible')) { + return Promise.reject({}); + } + return Promise.resolve([]); + }); + } - mockUserAPI.getCurrentUser - .and.returnValue( - Promise.resolve({ - id: 'someUser', - name: 'someUser' - }) - ); + return namespace; + }); - mockOpenmct = { - user: mockUserAPI - }; + mockUserAPI = jasmine.createSpyObj('userAPI', [ + 'getCurrentUser' + ]); + + mockUserAPI.getCurrentUser + .and.returnValue( + Promise.resolve({ + id: 'someUser', + name: 'someUser' + }) + ); + + mockOpenmct = { + user: mockUserAPI + }; + + sharedRootDefinition = { + id: 'shared:root', + key: 'shared', + name: 'Shared', + url: '/some/shared/namespace' + }; + inaccessibleSharedRootDefinition = { + id: 'inaccessible-shared:root', + key: 'inaccessible-shared', + name: 'Inaccessible Shared', + url: '/inaccessible/shared/namespace' + }; + missingSharedRootDefinition = { + id: 'missing-shared:root', + key: 'missing-shared', + name: 'Missing Shared', + url: '/missing/shared/namespace' + }; + + sharedRootDefinitions = [ + sharedRootDefinition, + inaccessibleSharedRootDefinition, + missingSharedRootDefinition + ]; + + containerRootDefinition = { + id: 'personal', + key: 'personal', + name: 'personal', + url: '/some/personal/namespace', + containsNamespaces: true, + childTemplate: { + id: 'personal-${USER}:root', + key: 'personal-${USER}', + name: '${USER}', + url: '/some/personal/namespace/${USER}' + } + }; + inaccessibleContainerRootDefinition = { + id: 'inaccessible-personal', + key: 'inaccessible-personal', + name: 'inaccessible-personal', + url: '/inaccessible/personal/namespace', + containsNamespaces: true, + childTemplate: { + id: 'inaccessible-personal-${USER}:root', + key: 'inaccessible-personal-${USER}', + name: '${USER}', + url: '/inaccessible/personal/namespace/${USER}' + } + }; + missingContainerRootDefinition = { + id: 'missing-personal:container', + key: 'missing-personal', + name: 'missing-personal', + url: '/missing/personal/namespace', + containsNamespaces: true, + childTemplate: { + id: 'missing-personal-${USER}:root', + key: 'missing-personal-${USER}', + name: '${USER}', + url: '/missing/personal/namespace/${USER}' + } + }; - sharedRootDefinition = { - id: 'shared:root', - key: 'shared', - name: 'Shared', - url: '/some/shared/namespace' - }; - inaccessibleSharedRootDefinition = { - id: 'inaccessible-shared:root', - key: 'inaccessible-shared', - name: 'Inaccessible Shared', - url: '/inaccessible/shared/namespace' - }; - missingSharedRootDefinition = { - id: 'missing-shared:root', - key: 'missing-shared', - name: 'Missing Shared', - url: '/missing/shared/namespace' - }; + containerRootDefinitions = [ + containerRootDefinition, + missingContainerRootDefinition, + inaccessibleContainerRootDefinition + ]; - sharedRootDefinitions = [ - sharedRootDefinition, - inaccessibleSharedRootDefinition, - missingSharedRootDefinition - ]; + mcwsPersistenceProvider = new MCWSPersistenceProvider( + mockOpenmct, + sharedRootDefinitions.concat(containerRootDefinitions) + ); - containerRootDefinition = { - id: 'personal', - key: 'personal', - name: 'personal', - url: '/some/personal/namespace', - containsNamespaces: true, - childTemplate: { - id: 'personal-${USER}:root', - key: 'personal-${USER}', - name: '${USER}', - url: '/some/personal/namespace/${USER}' - } - }; - inaccessibleContainerRootDefinition = { - id: 'inaccessible-personal', - key: 'inaccessible-personal', - name: 'inaccessible-personal', - url: '/inaccessible/personal/namespace', - containsNamespaces: true, - childTemplate: { - id: 'inaccessible-personal-${USER}:root', - key: 'inaccessible-personal-${USER}', - name: '${USER}', - url: '/inaccessible/personal/namespace/${USER}' - } - }; - missingContainerRootDefinition = { - id: 'missing-personal', - key: 'missing-personal', - name: 'missing-personal', - url: '/missing/personal/namespace', - containsNamespaces: true, - childTemplate: { - id: 'missing-personal-${USER}:root', - key: 'missing-personal-${USER}', - name: '${USER}', - url: '/missing/personal/namespace/${USER}' - } - }; + mcwsUserContainerProvider = new MCWSUserContainerProvider( + mockOpenmct, + containerRootDefinitions + ); + }); - containerRootDefinitions = [ - containerRootDefinition, - missingContainerRootDefinition, - inaccessibleContainerRootDefinition - ]; + describe('getRootNamespaces in MCWSUserContainerProvider', () => { + let result; - namespaceService = new MCWSNamespaceService( - mockOpenmct, - $window, - sharedRootDefinitions.concat(containerRootDefinitions) - ); + beforeEach(async () => { + result = await mcwsUserContainerProvider.getRootNamespaces(); }); - describe('getRootNamespaces', function () { - var result; + it('returns container namespaces', () => { + expect(result).toContain(containerRootDefinition); + }); - beforeEach(function (done) { - namespaceService - .getRootNamespaces() - .then(function (namespaceDefinitions) { - result = namespaceDefinitions; - }) - .then(done); - }); + it('creates missing container namespaces ', () => { + expect(result).toContain(missingContainerRootDefinition); + }); - it('returns container namespaces', function () { - expect(result).toContain(containerRootDefinition); - }); + it('removes inaccessible container namespaces', () => { + expect(result) + .not + .toContain(inaccessibleContainerRootDefinition); + }); + }); - it('creates missing container namespaces ', function () { - expect(result).toContain(missingContainerRootDefinition); - }); + describe('getRootNamespaces in MCWSPersistenceProvider', () => { + let result; - it('removes inaccessible container namespaces', function () { - expect(result) - .not - .toContain(inaccessibleContainerRootDefinition); - }); + beforeEach(async () => { + result = await mcwsPersistenceProvider.getRootNamespaces(); + }); - it('returns normal namespaces', function () { - expect(result).toContain(sharedRootDefinition); - }); + it('returns normal namespaces', () => { + expect(result).toContain(sharedRootDefinition); + }); - it('creates missing normal namespaces ', function () { - expect(result).toContain(missingSharedRootDefinition); - }); + it('creates missing normal namespaces ', () => { + expect(result).toContain(missingSharedRootDefinition); + }); - it('removes inaccessible normal namespaces', function () { - expect(result).not.toContain(inaccessibleSharedRootDefinition); - }); + it('removes inaccessible normal namespaces', () => { + expect(result).not.toContain(inaccessibleSharedRootDefinition); }); + }); - describe('getContainedNamespaces', function () { - var userRootNamespaceMIO, - userNamespaceMIO, - otherUserNamespaceMIO; + describe('getContainedNamespaces', () => { + let userRootNamespaceMIO, + userNamespaceMIO, + otherUserNamespaceMIO; + + beforeEach(() => { + const namespaceMIOs = {}; + mcws.namespace.and.callFake((namespaceUrl) => namespaceMIOs[namespaceUrl]); + + userRootNamespaceMIO = + namespaceMIOs['/some/personal/namespace'] = + jasmine.createSpyObj( + 'userNamespace', + ['read', 'create'] + ); + userRootNamespaceMIO.read.and.returnValue(Promise.resolve([])); - beforeEach(function () { - var namespaceMIOs = {}; - mcws.namespace.and.callFake(function (namespaceUrl) { - return namespaceMIOs[namespaceUrl]; - }); - userRootNamespaceMIO = - namespaceMIOs['/some/personal/namespace'] = - jasmine.createSpyObj( - 'userNamespace', - ['read', 'create'] - ); - userRootNamespaceMIO.read.and.returnValue(Promise.resolve([])); + userNamespaceMIO = + namespaceMIOs['/some/personal/namespace/someUser'] = + jasmine.createSpyObj( + 'userNamespaceMIO', + ['read', 'create'] + ); + userNamespaceMIO.read.and.returnValue(Promise.resolve([])); - userNamespaceMIO = - namespaceMIOs['/some/personal/namespace/someUser'] = - jasmine.createSpyObj( - 'userNamespaceMIO', - ['read', 'create'] - ); - userNamespaceMIO.read.and.returnValue(Promise.resolve([])); + otherUserNamespaceMIO = + namespaceMIOs['/some/personal/namespace/otherUser'] = + jasmine.createSpyObj( + 'otherUserNamespace', + ['read', 'create'] + ); - otherUserNamespaceMIO = - namespaceMIOs['/some/personal/namespace/otherUser'] = - jasmine.createSpyObj( - 'otherUserNamespace', - ['read', 'create'] - ); + otherUserNamespaceMIO.read.and.returnValue(Promise.resolve([])); + }); - otherUserNamespaceMIO.read.and.returnValue(Promise.resolve([])); - }); + function expectCurrentUserDefinition(definition) { + expect(definition.id).toBe('personal-someUser:root'); + expect(definition.key).toBe('personal-someUser'); + expect(definition.name).toBe('someUser'); + expect(definition.url).toBe('/some/personal/namespace/someUser'); + expect(definition.location).toBe('personal'); + }; + + function expectOtherUserDefinition(definition) { + expect(definition.id).toBe('personal-otherUser:root'); + expect(definition.key).toBe('personal-otherUser'); + expect(definition.name).toBe('otherUser'); + expect(definition.url).toBe('/some/personal/namespace/otherUser'); + expect(definition.location).toBe('personal'); + }; + + it('returns contents with current user first', async () => { + userRootNamespaceMIO.read.and.returnValue(Promise.resolve([ + { + object: 'namespace', + subject: '/some/personal/namespace/otherUser' + }, + { + object: 'namespace', + subject: '/some/personal/namespace/someUser' + } + ])); - function expectCurrentUserDefinition(definition) { - expect(definition.id).toBe('personal-someUser:root'); - expect(definition.key).toBe('personal-someUser'); - expect(definition.name).toBe('someUser'); - expect(definition.url) - .toBe('/some/personal/namespace/someUser'); - expect(definition.location).toBe('personal'); - } + const contents = await mcwsUserContainerProvider.getContainedNamespaces(containerRootDefinition); + expect(userNamespaceMIO.create).not.toHaveBeenCalled(); + expect(otherUserNamespaceMIO.create).not.toHaveBeenCalled(); - function expectOtherUserDefinition(definition) { - expect(definition.id).toBe('personal-otherUser:root'); - expect(definition.key).toBe('personal-otherUser'); - expect(definition.name).toBe('otherUser'); - expect(definition.url) - .toBe('/some/personal/namespace/otherUser'); - expect(definition.location).toBe('personal'); - } + expect(contents.length).toBe(2); + expectCurrentUserDefinition(contents[0]); + expectOtherUserDefinition(contents[1]); + }); - it('returns contents with current user first', function (done) { - userRootNamespaceMIO.read.and.returnValue(Promise.resolve([ - { - object: 'namespace', - subject: '/some/personal/namespace/otherUser' - }, - { - object: 'namespace', - subject: '/some/personal/namespace/someUser' - } - ])); - - namespaceService - .getContainedNamespaces(containerRootDefinition) - .then(function (contents) { - expect(userNamespaceMIO.create) - .not - .toHaveBeenCalled(); - expect(otherUserNamespaceMIO.create) - .not - .toHaveBeenCalled(); - - expect(contents.length).toBe(2); - expectCurrentUserDefinition(contents[0]); - expectOtherUserDefinition(contents[1]); - }) - .then(done); - }); + it('creates user if missing', async () => { + userRootNamespaceMIO.read.and.returnValue(Promise.resolve([])); + userNamespaceMIO.read.and.returnValue(Promise.reject({status: 404})); + userNamespaceMIO.create.and.returnValue(Promise.resolve([])); - it('creates user if missing', function (done) { - userRootNamespaceMIO.read.and.returnValue(Promise.resolve([])); - userNamespaceMIO.read.and.returnValue(Promise.reject({status: 404})); - userNamespaceMIO.create.and.returnValue(Promise.resolve([])); - - namespaceService - .getContainedNamespaces(containerRootDefinition) - .then(function (contents) { - expect(contents.length).toBe(1); - expect(userNamespaceMIO.create) - .toHaveBeenCalled(); - expectCurrentUserDefinition(contents[0]); - }) - .then(done); - }); + const contents = await mcwsUserContainerProvider.getContainedNamespaces(containerRootDefinition); + expect(contents.length).toBe(1); + expect(userNamespaceMIO.create).toHaveBeenCalled(); + expectCurrentUserDefinition(contents[0]); }); + }); - describe('namespace filtering', function () { - var smapDefinition, - mslDefinition, - ammosDefinition, - filterDefinitions; - - beforeEach(function () { - smapDefinition = { - key: 'smap-thing', - url: '/path/to/smap-namespace' - }; - mslDefinition = { - key: 'msl-thing', - url: '/path/to/msl-namespace' - }; - ammosDefinition = { - key: 'ammos-thing', - url: '/path/to/ammos-namespace' - }; - filterDefinitions = [ - smapDefinition, - mslDefinition, - ammosDefinition - ]; - - namespaceService = new MCWSNamespaceService( - mockOpenmct, - $window, - filterDefinitions - ); + // need to fix this (issue is mocking window.location.pathname) + xdescribe('namespace filtering', () => { + let smapDefinition; + let mslDefinition; + let ammosDefinition; + let filterDefinitions; + let filterPath = '/mcws/clients/vista/'; + let filterTerm = 'vista'; + + beforeEach(() => { + spyOn(String.prototype, 'startsWith').and.callFake(function(searchString) { + if (searchString.includes('/') && searchString === filterPath) { + return true; + } else if (searchString.includes(filterTerm)) { + return true; + } + return false; }); - it('does not filter with default path', function (done) { - namespaceService - .getRootNamespaces() - .then(function (namespaces) { - expect(namespaces).toEqual(filterDefinitions); - }) - .then(done); - }); + smapDefinition = { + key: 'smap-thing', + url: '/path/to/smap-namespace' + }; + mslDefinition = { + key: 'msl-thing', + url: '/path/to/msl-namespace' + }; + ammosDefinition = { + key: 'ammos-thing', + url: '/path/to/ammos-namespace' + }; + filterDefinitions = [ + smapDefinition, + mslDefinition, + ammosDefinition + ]; - it('only includes smap with smap-path', function (done) { - $window.location.pathname = '/mcws/clients/vista-smap/'; - namespaceService - .getRootNamespaces() - .then(function (namespaces) { - expect(namespaces).toEqual([smapDefinition]); - }) - .then(done); - }); + mcwsPersistenceProvider = new MCWSPersistenceProvider( + mockOpenmct, + filterDefinitions + ); + }); - it('only includes msl with msl-path', function (done) { - $window.location.pathname = '/mcws/clients/vista-msl/'; - namespaceService - .getRootNamespaces() - .then(function (namespaces) { - expect(namespaces).toEqual([mslDefinition]); - }) - .then(done); - }); + afterEach(() => { + String.prototype.startsWith.and.callThrough(); + }); - it('only includes ammos with ammos-path', function (done) { - $window.location.pathname = '/mcws/clients/vista-ammos/'; - namespaceService - .getRootNamespaces() - .then(function (namespaces) { - expect(namespaces).toEqual([ammosDefinition]); - }) - .then(done); - }); + it('does not filter with default path', async () => { + const namespaces = await mcwsPersistenceProvider.getRootNamespaces(); + expect(namespaces).toEqual(filterDefinitions); + }); + + it('only includes smap with smap-path', async () => { + filterPath = '/mcws/clients/vista-smap'; + filterTerm = 'smap'; + const namespaces = await mcwsPersistenceProvider.getRootNamespaces(); + expect(namespaces).toEqual([smapDefinition]); + }); + + it('only includes msl with msl-path', async () => { + filterPath = '/mcws/clients/vista-msl'; + filterTerm = 'msl'; + const namespaces = await mcwsPersistenceProvider.getRootNamespaces(); + expect(namespaces).toEqual([mslDefinition]); + }); + + it('only includes ammos with ammos-path', async () => { + filterPath = '/mcws/clients/vista-ammos'; + filterTerm = 'ammos'; + const namespaces = await mcwsPersistenceProvider.getRootNamespaces(); + expect(namespaces).toEqual([ammosDefinition]); }); }); }); diff --git a/src/persistence/test/MCWSPersistenceProviderSpec.js b/src/persistence/test/MCWSPersistenceProviderSpec.js index 566fedc..5a9132e 100644 --- a/src/persistence/test/MCWSPersistenceProviderSpec.js +++ b/src/persistence/test/MCWSPersistenceProviderSpec.js @@ -1,189 +1,186 @@ -/*global define,Promise,describe,it,expect,beforeEach,jasmine*/ - -define([ - // "../src/MCWSPersistenceProvider", - // '../../../services/mcws/mcws' -], function ( - // MCWSPersistenceProvider, - // mcwsDefault -) { - "use strict"; - - // const mcws = mcwsDefault.default; - - xdescribe("The MCWS Persistence Provider", function () { - var mockQ, - mockNamespaceService, - persistenceNamespaces, - mockNamespace, - mockOpaqueFile, - persistence; - - beforeEach(function () { - mockQ = jasmine.createSpyObj("$q", ["when"]); - spyOn(mcws, 'namespace'); - mockNamespaceService = jasmine.createSpyObj( - "namespaceService", - ["getPersistenceNamespaces"] - ); - persistenceNamespaces = [ - { - key: "testSpace", - url: "/test/namespace" - }, - { - key: "testSpace2", - url: "/test/namespace2" - } - ]; - - mockNamespaceService - .getPersistenceNamespaces - .and.returnValue(Promise.resolve(persistenceNamespaces)); - - - mockNamespace = - jasmine.createSpyObj("namespace", ["opaqueFile", "read"]); - mockOpaqueFile = jasmine.createSpyObj("opaqueFile", [ - "read", - "replace", - "remove", - "create" - ]); - - mockQ.when.and.callFake(function (resolver) { - return Promise.resolve(resolver); - }); - - mcws.namespace.and.returnValue(mockNamespace); - mockNamespace.opaqueFile.and.returnValue(mockOpaqueFile); - - persistence = new MCWSPersistenceProvider( - mockQ, - mockNamespaceService - ); - }); - - it("provides a promise for available spaces", function (done) { - persistence.listSpaces() - .then(function (spaces) { - expect(spaces).toEqual(['testSpace', 'testSpace2']); - done(); - }) - }); +import MCWSPersistenceProvider from '../MCWSPersistenceProvider'; +import mcws from 'services/mcws/mcws'; + +describe('The MCWS Persistence Provider', () => { + let mockNamespaceService; + let persistenceNamespaces; + let mockNamespace; + let mockOpaqueFile; + let openmct; + let mcwsPersistenceProvider; + + beforeEach(() => { + openmct = { + user: { + getCurrentUser: () => Promise.resolve({ id: 'myUser' }) + } + }; + + spyOn(mcws, 'namespace'); + mockNamespaceService = jasmine.createSpyObj( + 'namespaceService', + ['getPersistenceNamespaces'] + ); + + persistenceNamespaces = [ + { + key: 'testSpace', + url: '/test/namespace' + }, + { + key: 'testSpace2', + url: '/test/namespace2' + } + ]; + + mockNamespaceService + .getPersistenceNamespaces + .and.returnValue(Promise.resolve(persistenceNamespaces)); + + + mockNamespace = + jasmine.createSpyObj('namespace', ['opaqueFile', 'read']); + mockOpaqueFile = jasmine.createSpyObj('opaqueFile', [ + 'read', + 'replace', + 'remove', + 'create' + ]); + + mcws.namespace.and.returnValue(mockNamespace); + mockNamespace.opaqueFile.and.returnValue(mockOpaqueFile); + + mcwsPersistenceProvider = new MCWSPersistenceProvider( + openmct, + persistenceNamespaces + ); + }); - it("provides a listing of identifiers", function (done) { - mockNamespace.read.and.returnValue(Promise.resolve([ - { - Subject: "/test/namespace/a", - Predicate: "has MIO type", - Object: "opaque_file" - }, - { - Subject: "/test/namespace/b", - Predicate: "has MIO type", - Object: "namespace" - }, - { - Subject: "/test/namespace/c", - Predicate: "something else", - Object: "opaque_file" - }, - { - Subject: "/some/namespace/xyz", - Predicate: "has MIO type", - Object: "opaque_file" - }, - { - Subject: "/some/namespace/123-ABC", - Predicate: "has MIO type", - Object: "opaque_file" - } - ])); - persistence - .listObjects("testSpace") - .then(function (objects) { - expect(objects).toEqual(["a", "xyz", "123-ABC"]); - done(); - }); - }); + it('provides a promise for available namespaces', async (done) => { + const spaces = await mcwsPersistenceProvider.getPersistenceNamespaces(); + expect(spaces).toEqual(persistenceNamespaces); + done(); + }); + + // DO WE DELETE THIS TEST? I don't think we use this functionality anymore. + xit('provides a listing of namespaces when provided a namespace definition', async (done) => { + const namespaceTriples = [ + { + Subject: '/test/namespace/a', + Predicate: 'has MIO type', + Object: 'opaque_file' + }, + { + Subject: '/test/namespace/b', + Predicate: 'has MIO type', + Object: 'namespace' + }, + { + Subject: '/test/namespace/c', + Predicate: 'something else', + Object: 'opaque_file' + }, + { + Subject: '/some/namespace/xyz', + Predicate: 'has MIO type', + Object: 'opaque_file' + }, + { + Subject: '/some/namespace/123-ABC', + Predicate: 'has MIO type', + Object: 'opaque_file' + } + ]; + mockNamespace.read.and.returnValue(Promise.resolve(namespaceTriples)); + + const objects = await mcwsPersistenceProvider.getNamespacesFromMCWS({ url: '/test/namespace' }); + expect(objects).toEqual(namespaceTriples); + done(); + }); - it("allows objects to be created", function (done) { - mockOpaqueFile.create.and.returnValue(Promise.resolve(true)); - persistence - .createObject( - "testSpace", - "testKey", - { someKey: "some value" } - ) - .then(function (result) { - expect(result).toBe(true); - expect(mockNamespace.opaqueFile) - .toHaveBeenCalledWith("testKey"); - expect(mockOpaqueFile.create) - .toHaveBeenCalledWith({ someKey: "some value" }); - done(); - }); - }); + it('allows objects to be created', async (done) => { + mockOpaqueFile.create.and.returnValue(Promise.resolve(true)); + const domainObject = { + identifier: { + key: 'testKey', + namespace: 'testSpace' + }, + someKey: 'some value' + }; + const result = await mcwsPersistenceProvider.create(domainObject); + + expect(result).toBe(true); + expect(mockNamespace.opaqueFile) + .toHaveBeenCalledWith('testKey'); + expect(mockOpaqueFile.create) + .toHaveBeenCalledWith({ someKey: 'some value' }); + done(); + }); - it("allows objects to be read", function (done) { - mockOpaqueFile.read.and.returnValue(Promise.resolve("test object")); - persistence - .readObject("testSpace", "testKey") - .then(function (object) { - expect(object).toBe("test object"); - expect(mcws.namespace) - .toHaveBeenCalledWith("/test/namespace"); - expect(mockNamespace.opaqueFile) - .toHaveBeenCalledWith("testKey"); - expect(mockOpaqueFile.read) - .toHaveBeenCalled(); - done(); - }); - }); + it('allows objects to be read', async (done) => { + const identifier = { + key: 'testKey', + namespace: 'testSpace' + }; + const model = { + someKey: 'some value' + }; + const domainObject = { + identifier, + ...model + }; + mockOpaqueFile.read.and.returnValue(Promise.resolve({json: () => Promise.resolve(model)})); + const object = await mcwsPersistenceProvider.get(identifier); + + expect(object).toEqual(domainObject); + expect(mcws.namespace) + .toHaveBeenCalledWith('/test/namespace'); + expect(mockNamespace.opaqueFile) + .toHaveBeenCalledWith('testKey'); + expect(mockOpaqueFile.read) + .toHaveBeenCalled(); + done(); + }); - it("allows objects to be updated", function (done) { - mockOpaqueFile.replace.and.returnValue(Promise.resolve(true)); - persistence - .updateObject( - "testSpace", - "testKey", - { someKey: "some value" } - ) - .then(function (result) { - expect(result).toBe(true); - expect(mcws.namespace) - .toHaveBeenCalledWith("/test/namespace"); - expect(mockNamespace.opaqueFile) - .toHaveBeenCalledWith("testKey"); - expect(mockOpaqueFile.replace) - .toHaveBeenCalledWith({ someKey: "some value" }); - done(); - }) - }); + it('allows objects to be updated', async (done) => { + mockOpaqueFile.replace.and.returnValue(Promise.resolve(true)); + const domainObject = { + identifier: { + key: 'testKey', + namespace: 'testSpace' + }, + someKey: 'some value' + }; + const result = await mcwsPersistenceProvider.update(domainObject); + + expect(result).toBe(true); + expect(mcws.namespace) + .toHaveBeenCalledWith('/test/namespace'); + expect(mockNamespace.opaqueFile) + .toHaveBeenCalledWith('testKey'); + expect(mockOpaqueFile.replace) + .toHaveBeenCalledWith({ someKey: 'some value' }); + done(); + }); - it("allows objects to be deleted", function (done) { - mockOpaqueFile.remove.and.returnValue(Promise.resolve(true)); - persistence - .deleteObject("testSpace", "testKey") - .then(function (result) { - expect(mcws.namespace) - .toHaveBeenCalledWith("/test/namespace"); - expect(mockNamespace.opaqueFile) - .toHaveBeenCalledWith("testKey"); - expect(mockOpaqueFile.remove).toHaveBeenCalled(); - done(); - }) - }); + // We don't allow delete in the core API, so we don't need this test. + xit('allows objects to be deleted', async (done) => { + mockOpaqueFile.remove.and.returnValue(Promise.resolve(true)); + await mcwsPersistenceProvider.delete({ key: 'testKey', namespace: 'testSpace' }); + + expect(mcws.namespace) + .toHaveBeenCalledWith('/test/namespace'); + expect(mockNamespace.opaqueFile) + .toHaveBeenCalledWith('testKey'); + expect(mockOpaqueFile.remove).toHaveBeenCalled(); + done(); + }); - it("converts rejected promises to promises resolves to undefined", function (done) { - mockOpaqueFile.read.and.returnValue(Promise.reject("hello")); - persistence - .readObject("testSpace", "testKey") - .then(function (result) { - expect(result).toBeUndefined(); - done(); - }) - }); + it('converts rejected promises to promises resolves to undefined', async (done) => { + mockOpaqueFile.read.and.returnValue(Promise.reject('hello')); + const result = await mcwsPersistenceProvider.get({ key: 'testKey', namespace: 'testSpace' }); + + expect(result).toBeUndefined(); + done(); }); }); diff --git a/src/product-status/DataProductRowSpec.js b/src/product-status/DataProductRowSpec.js index 42bfbc0..97f1e11 100644 --- a/src/product-status/DataProductRowSpec.js +++ b/src/product-status/DataProductRowSpec.js @@ -1,206 +1,198 @@ -/*global define,describe,beforeEach,it,expect*/ +import DataProductRow from './DataProductRow'; -define([ - './DataProductRow' -], function ( - DataProductRow -) { - 'use strict'; +describe('The Data Product Row', () => { + let dataProductRow; + let columns; + let objectKeyString; + let limitEvaluator; + let rowId; + let startMessage; + let partReceivedMessage; + let completeMessage; - describe('The Data Product Row', function () { - let dataProductRow; - let columns; - let objectKeyString; - let limitEvaluator; - let rowId; - let startMessage; - let partReceivedMessage; - let completeMessage; - - beforeEach(function () { - columns = []; - objectKeyString = 'test-object'; - limitEvaluator = { - evaluate: function () {return {}} - }; - rowId = 'test-row-id'; - startMessage = { - "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", - "session_host":"host", - "apid":"424", - "total_parts":"0", - "session_id":"36", - "record_type":"product_started", - "part_number":"0", - "event_time":"2019-259T17:06:54.691", - "vcid":"32" - }; - partReceivedMessage = { - "creation_time":"", - "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", - "dvt_coarse":"457586851", - "ground_status":"UNKNOWN", - "session_host":"host", - "ert":"2019-259T17:06:54.590", - "dvt_fine":"19880", - "apid":"424", - "total_parts":"0", - "session_id":"36", - "scet":"2014-183T15:39:04.687010296", - "lst":"", - "version":"", - "file_size":"0", - "record_type":"product_part_received", - "command_number":"0", - "unique_name":"products\/McamRThumbnail\/McamRThumbnail_0457586851-19880", - "seq_version":"0", - "checksum":"0", - "part_number":"0", - "sclk":"0457586851.30334", - "seq_id":"0", - "event_time":"2019-259T17:06:54.691", - "vcid":"32" - }; - completeMessage = { - "creation_time":"2019-259T17:06:57.800", - "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", - "dvt_coarse":"457586851", - "ground_status":"COMPLETE_CHECKSUM_PASS", - "session_host":"host", - "ert":"2019-259T17:06:54.590", - "dvt_fine":"19880", - "apid":"424", - "total_parts":"20", - "session_id":"36", - "scet":"2014-183T15:39:04.687010296", - "lst":"", - "version":"", - "file_size":"192819", - "record_type":"complete_product", - "command_number":"2", - "unique_name":"complete_product_unique_name", - "seq_version":"0", - "checksum":"33862", - "sclk":"0457586851.30334", - "seq_id":"0", - "event_time":"2019-259T17:06:54.691", - "vcid":"32" - } - }); + beforeEach(() => { + columns = []; + objectKeyString = 'test-object'; + limitEvaluator = { + evaluate: () => ({}) + }; + rowId = 'test-row-id'; + startMessage = { + "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", + "session_host":"host", + "apid":"424", + "total_parts":"0", + "session_id":"36", + "record_type":"product_started", + "part_number":"0", + "event_time":"2019-259T17:06:54.691", + "vcid":"32" + }; + partReceivedMessage = { + "creation_time":"", + "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", + "dvt_coarse":"457586851", + "ground_status":"UNKNOWN", + "session_host":"host", + "ert":"2019-259T17:06:54.590", + "dvt_fine":"19880", + "apid":"424", + "total_parts":"0", + "session_id":"36", + "scet":"2014-183T15:39:04.687010296", + "lst":"", + "version":"", + "file_size":"0", + "record_type":"product_part_received", + "command_number":"0", + "unique_name":"products\/McamRThumbnail\/McamRThumbnail_0457586851-19880", + "seq_version":"0", + "checksum":"0", + "part_number":"0", + "sclk":"0457586851.30334", + "seq_id":"0", + "event_time":"2019-259T17:06:54.691", + "vcid":"32" + }; + completeMessage = { + "creation_time":"2019-259T17:06:57.800", + "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", + "dvt_coarse":"457586851", + "ground_status":"COMPLETE_CHECKSUM_PASS", + "session_host":"host", + "ert":"2019-259T17:06:54.590", + "dvt_fine":"19880", + "apid":"424", + "total_parts":"20", + "session_id":"36", + "scet":"2014-183T15:39:04.687010296", + "lst":"", + "version":"", + "file_size":"192819", + "record_type":"complete_product", + "command_number":"2", + "unique_name":"complete_product_unique_name", + "seq_version":"0", + "checksum":"33862", + "sclk":"0457586851.30334", + "seq_id":"0", + "event_time":"2019-259T17:06:54.691", + "vcid":"32" + } + }); - it('Sets received parts to 0 when start message received', function () { - dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); - expect(dataProductRow.datum.parts_received).toBe(0); - }); + it('Sets received parts to 0 when start message received', () => { + dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); + expect(dataProductRow.datum.parts_received).toBe(0); + }); - it('Increments part count when product part message received', function () { - dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); - expect(dataProductRow.datum.parts_received).toBe(0); - dataProductRow.update(partReceivedMessage); - expect(dataProductRow.datum.parts_received).toBe(1); - }); + it('Increments part count when product part message received', () => { + dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); + expect(dataProductRow.datum.parts_received).toBe(0); + dataProductRow.update(partReceivedMessage); + expect(dataProductRow.datum.parts_received).toBe(1); + }); - it('Replaces content of in progress rows with info from new message', function () { - const secondPartReceived = { - "creation_time":"", - "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", - "dvt_coarse":"457586851", - "ground_status":"UNKNOWN", - "session_host":"host", - "ert":"2019-259T17:06:54.590", - "dvt_fine":"19880", - "apid":"424", - "total_parts":"0", - "session_id":"36", - "scet":"2014-183T15:39:04.687010296", - "lst":"", - "version":"", - "file_size":"0", - "record_type":"product_part_received", - "command_number":"0", - "unique_name":"a_different_unique_name", - "seq_version":"0", - "checksum":"1234", - "part_number":"2", - "sclk":"0457586851.30334", - "seq_id":"0", - "event_time":"2019-259T17:06:54.691", - "vcid":"32" - }; + it('Replaces content of in progress rows with info from new message', () => { + const secondPartReceived = { + "creation_time":"", + "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", + "dvt_coarse":"457586851", + "ground_status":"UNKNOWN", + "session_host":"host", + "ert":"2019-259T17:06:54.590", + "dvt_fine":"19880", + "apid":"424", + "total_parts":"0", + "session_id":"36", + "scet":"2014-183T15:39:04.687010296", + "lst":"", + "version":"", + "file_size":"0", + "record_type":"product_part_received", + "command_number":"0", + "unique_name":"a_different_unique_name", + "seq_version":"0", + "checksum":"1234", + "part_number":"2", + "sclk":"0457586851.30334", + "seq_id":"0", + "event_time":"2019-259T17:06:54.691", + "vcid":"32" + }; - dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); + dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); - dataProductRow.update(partReceivedMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); - expect(dataProductRow.datum["checksum"]).toEqual("0"); - expect(dataProductRow.datum["part_number"]).toEqual("0"); + dataProductRow.update(partReceivedMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); + expect(dataProductRow.datum["checksum"]).toEqual("0"); + expect(dataProductRow.datum["part_number"]).toEqual("0"); - dataProductRow.update(secondPartReceived); - expect(dataProductRow.datum["unique_name"]).toEqual("a_different_unique_name"); - expect(dataProductRow.datum["checksum"]).toEqual("1234"); - expect(dataProductRow.datum["part_number"]).toEqual("2"); - expect(false); - }); + dataProductRow.update(secondPartReceived); + expect(dataProductRow.datum["unique_name"]).toEqual("a_different_unique_name"); + expect(dataProductRow.datum["checksum"]).toEqual("1234"); + expect(dataProductRow.datum["part_number"]).toEqual("2"); + expect(false); + }); - it('Does not replace content of complete rows with in progress rows', function () { - dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); - dataProductRow.update(partReceivedMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); - expect(dataProductRow.datum["checksum"]).toEqual("0"); - expect(dataProductRow.datum["part_number"]).toEqual("0"); - - dataProductRow.update(completeMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); - expect(dataProductRow.datum["checksum"]).toEqual("33862"); - expect(dataProductRow.datum["part_number"]).toBeUndefined(); + it('Does not replace content of complete rows with in progress rows', () => { + dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); + dataProductRow.update(partReceivedMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); + expect(dataProductRow.datum["checksum"]).toEqual("0"); + expect(dataProductRow.datum["part_number"]).toEqual("0"); + + dataProductRow.update(completeMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); + expect(dataProductRow.datum["checksum"]).toEqual("33862"); + expect(dataProductRow.datum["part_number"]).toBeUndefined(); - dataProductRow.update(partReceivedMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); - expect(dataProductRow.datum["checksum"]).toEqual("33862"); - expect(dataProductRow.datum["part_number"]).toBeUndefined(); - }); + dataProductRow.update(partReceivedMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); + expect(dataProductRow.datum["checksum"]).toEqual("33862"); + expect(dataProductRow.datum["part_number"]).toBeUndefined(); + }); - it('Does replace content of complete rows with complete rows', function () { - const aDifferentCompleteMessage = { - "creation_time":"2019-259T17:06:57.800", - "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", - "dvt_coarse":"457586851", - "ground_status":"COMPLETE_CHECKSUM_PASS", - "session_host":"host", - "ert":"2019-259T17:06:54.590", - "dvt_fine":"19880", - "apid":"424", - "total_parts":"20", - "session_id":"36", - "scet":"2014-183T15:39:04.687010296", - "lst":"", - "version":"", - "file_size":"192819", - "record_type":"complete_product", - "command_number":"2", - "unique_name":"a_different_complete_product_unique_name", - "seq_version":"0", - "checksum":"54321", - "sclk":"0457586851.30334", - "seq_id":"0", - "event_time":"2019-259T17:07:57.800", - "vcid":"32" - } - dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); - dataProductRow.update(partReceivedMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); - expect(dataProductRow.datum["checksum"]).toEqual("0"); - expect(dataProductRow.datum["part_number"]).toEqual("0"); - - dataProductRow.update(completeMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); - expect(dataProductRow.datum["checksum"]).toEqual("33862"); - expect(dataProductRow.datum["event_time"]).toEqual("2019-259T17:06:54.691"); + it('Does replace content of complete rows with complete rows', () => { + const aDifferentCompleteMessage = { + "creation_time":"2019-259T17:06:57.800", + "transaction_id":"McamRThumbnail\/McamRThumbnail_0457586851-19880", + "dvt_coarse":"457586851", + "ground_status":"COMPLETE_CHECKSUM_PASS", + "session_host":"host", + "ert":"2019-259T17:06:54.590", + "dvt_fine":"19880", + "apid":"424", + "total_parts":"20", + "session_id":"36", + "scet":"2014-183T15:39:04.687010296", + "lst":"", + "version":"", + "file_size":"192819", + "record_type":"complete_product", + "command_number":"2", + "unique_name":"a_different_complete_product_unique_name", + "seq_version":"0", + "checksum":"54321", + "sclk":"0457586851.30334", + "seq_id":"0", + "event_time":"2019-259T17:07:57.800", + "vcid":"32" + } + dataProductRow = new DataProductRow(startMessage, columns, objectKeyString, limitEvaluator, rowId); + dataProductRow.update(partReceivedMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("products\/McamRThumbnail\/McamRThumbnail_0457586851-19880"); + expect(dataProductRow.datum["checksum"]).toEqual("0"); + expect(dataProductRow.datum["part_number"]).toEqual("0"); + + dataProductRow.update(completeMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("complete_product_unique_name"); + expect(dataProductRow.datum["checksum"]).toEqual("33862"); + expect(dataProductRow.datum["event_time"]).toEqual("2019-259T17:06:54.691"); - dataProductRow.update(aDifferentCompleteMessage); - expect(dataProductRow.datum["unique_name"]).toEqual("a_different_complete_product_unique_name"); - expect(dataProductRow.datum["checksum"]).toEqual("54321"); - expect(dataProductRow.datum["event_time"]).toEqual("2019-259T17:07:57.800") - }); + dataProductRow.update(aDifferentCompleteMessage); + expect(dataProductRow.datum["unique_name"]).toEqual("a_different_complete_product_unique_name"); + expect(dataProductRow.datum["checksum"]).toEqual("54321"); + expect(dataProductRow.datum["event_time"]).toEqual("2019-259T17:07:57.800") }); }); diff --git a/src/services/session/test/controllers/SessionIndicatorControllerSpec.js b/src/services/session/test/controllers/SessionIndicatorControllerSpec.js index 64e2d1e..7e08d2c 100644 --- a/src/services/session/test/controllers/SessionIndicatorControllerSpec.js +++ b/src/services/session/test/controllers/SessionIndicatorControllerSpec.js @@ -1,189 +1,180 @@ -/*global define,describe,beforeEach,jasmine,Promise,it,spyOn,expect,waitsFor, - runs*/ - -define([ - // '../../src/controllers/SessionIndicatorController' -], function ( - // SessionIndicatorController -) { - 'use strict'; - - xdescribe('SessionIndicatorController', function () { - var $scope, +// import SessionIndicatorController from '../SessionIndicatorController'; + +// this would be better tested in an e2e test +xdescribe('SessionIndicatorController', function () { + let $scope; + let sessionService; + let overlayService; + let overlay; + let $timeout; + let controller; + + beforeEach(function () { + $scope = jasmine.createSpyObj('$scope', ['$digest']); + sessionService = jasmine.createSpyObj( + 'sessionService', + [ + 'setActiveTopicOrSession', + 'getActiveTopicOrSession', + 'getTopicsWithSessions', + 'listen' + ] + ); + sessionService.realtimeSessionConfig = { + disable: false + }; + sessionService.historicalSessionFilterConfig = { + disable: false, + maxRecords: 100 + }; + sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([])); + sessionService.getActiveTopicOrSession.and.returnValue('mySession'); + overlayService = jasmine.createSpyObj( + 'overlayService', + ['createOverlay'] + ); + overlay = jasmine.createSpyObj( + 'overlay', + ['dismiss'] + ); + overlayService.createOverlay.and.returnValue(overlay); + $timeout = jasmine.createSpy('$timeout'); + $timeout.cancel = jasmine.createSpy('timeout.cancel'); + + spyOn(SessionIndicatorController.prototype, 'pollForSessions'); + + controller = new SessionIndicatorController( + $scope, sessionService, overlayService, - overlay, - $timeout, - instantiate, - controller; + $timeout + ); + }); - beforeEach(function () { - $scope = jasmine.createSpyObj('$scope', ['$digest']); - sessionService = jasmine.createSpyObj( - 'sessionService', - [ - 'setActiveTopicOrSession', - 'getActiveTopicOrSession', - 'getTopicsWithSessions', - 'listen' - ] - ); - sessionService.realtimeSessionConfig = { - disable: false - }; - sessionService.historicalSessionFilterConfig = { - disable: false, - maxRecords: 100 - } - sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([])); - sessionService.getActiveTopicOrSession.and.returnValue('mySession'); - overlayService = jasmine.createSpyObj( - 'overlayService', - ['createOverlay'] - ); - overlay = jasmine.createSpyObj( - 'overlay', - ['dismiss'] - ); - overlayService.createOverlay.and.returnValue(overlay); - $timeout = jasmine.createSpy('$timeout'); - $timeout.cancel = jasmine.createSpy('timeout.cancel'); + it('polls for sessions on instantiation', function () { + expect(controller.pollForSessions).toHaveBeenCalled(); + }); - spyOn(SessionIndicatorController.prototype, 'pollForSessions'); + it('sets activeSession on instantiation', function () { + expect($scope.activeSession).toBe('mySession'); + }); - controller = new SessionIndicatorController( - $scope, - sessionService, - overlayService, - $timeout - ); + it('listens for and handles changes of active session', function () { + var callsToPoll = controller.pollForSessions.calls.all().length; + expect(sessionService.listen) + .toHaveBeenCalledWith(jasmine.any(Function)); + + sessionService.listen.calls.mostRecent().args[0]('anotherSession'); + expect($scope.activeSession).toBe('anotherSession'); + expect(controller.pollForSessions.calls.all().length) + .toBe(callsToPoll + 1); + }); + + describe('pollForSessions', function () { + beforeEach(function () { + // instantiate without calls so we can test. + controller.pollForSessions.calls.reset(); + controller.pollForSessions.and.callThrough(); }); - it('polls for sessions on instantiation', function () { - expect(controller.pollForSessions).toHaveBeenCalled(); + it('sets a timeout to poll sessions', function () { + controller.pollForSessions(); + expect($timeout) + .toHaveBeenCalledWith( + jasmine.any(Function), + jasmine.any(Number) + ); + + expect(controller.pollForSessions.calls.all().length).toBe(1); + $timeout.calls.mostRecent().args[0](); + expect(controller.pollForSessions.calls.all().length).toBe(2); }); - it('sets activeSession on instantiation', function () { + it('does not fetch sessions with active session', function () { expect($scope.activeSession).toBe('mySession'); + controller.pollForSessions(); + expect(sessionService.getTopicsWithSessions) + .not + .toHaveBeenCalled(); }); - it('listens for and handles changes of active session', function () { - var callsToPoll = controller.pollForSessions.calls.all().length; - expect(sessionService.listen) - .toHaveBeenCalledWith(jasmine.any(Function)); + describe('without active session', function () { + let digestPromise; - sessionService.listen.calls.mostRecent().args[0]('anotherSession'); - expect($scope.activeSession).toBe('anotherSession'); - expect(controller.pollForSessions.calls.all().length) - .toBe(callsToPoll + 1); - }); + beforeEach(function (done) { + digestPromise = new Promise((resolve, reject) => { + $scope.activeSession = undefined; + expect(typeof $scope.hasTopics).toBe('undefined'); + expect(sessionService.getTopicsWithSessions) + .not + .toHaveBeenCalled(); - describe('pollForSessions', function () { - beforeEach(function () { - // instantiate without calls so we can test. - controller.pollForSessions.calls.reset(); - controller.pollForSessions.and.callThrough(); + $scope.$digest.and.callFake(resolve); + done(); + }); }); - it('sets a timeout to poll sessions', function () { - controller.pollForSessions(); - expect($timeout) - .toHaveBeenCalledWith( - jasmine.any(Function), - jasmine.any(Number) - ); - - expect(controller.pollForSessions.calls.all().length).toBe(1); - $timeout.calls.mostRecent().args[0](); - expect(controller.pollForSessions.calls.all().length).toBe(2); - }); - it('does not fetch sessions with active session', function () { - expect($scope.activeSession).toBe('mySession'); + it('fetches sessions', function () { controller.pollForSessions(); expect(sessionService.getTopicsWithSessions) - .not .toHaveBeenCalled(); + // Ensure async tasks finish before other specs. + return digestPromise; }); - describe('without active session', function () { - let digestPromise; - - beforeEach(function (done) { - digestPromise = new Promise((resolve, reject) => { - $scope.activeSession = undefined; - expect(typeof $scope.hasTopics).toBe('undefined'); - expect(sessionService.getTopicsWithSessions) - .not - .toHaveBeenCalled(); - - $scope.$digest.and.callFake(resolve); - done(); - }); - }); - - - it('fetches sessions', function () { - controller.pollForSessions(); - expect(sessionService.getTopicsWithSessions) - .toHaveBeenCalled(); - // Ensure async tasks finish before other specs. - return digestPromise; - }); - - it('sets hasTopic to false when no topics exist', function () { - sessionService - .getTopicsWithSessions - .and.returnValue(Promise.resolve([])); - controller.pollForSessions(); - return digestPromise.then(() => { - expect($scope.hasTopics).toBe(false); - }); + it('sets hasTopic to false when no topics exist', function () { + sessionService + .getTopicsWithSessions + .and.returnValue(Promise.resolve([])); + controller.pollForSessions(); + return digestPromise.then(() => { + expect($scope.hasTopics).toBe(false); }); + }); - it('sets hasTopic to true when topics exist', function () { - sessionService - .getTopicsWithSessions - .and.returnValue(Promise.resolve([ - 'a', - 'b' - ])); - controller.pollForSessions(); - return digestPromise.then(() => { - expect($scope.hasTopics).toBe(true); - }); + it('sets hasTopic to true when topics exist', function () { + sessionService + .getTopicsWithSessions + .and.returnValue(Promise.resolve([ + 'a', + 'b' + ])); + controller.pollForSessions(); + return digestPromise.then(() => { + expect($scope.hasTopics).toBe(true); }); - }); - }); - describe('selectSession', function () { + }); + }); - beforeEach(function () { - controller.selectSession(); - }); + describe('selectSession', function () { - it('opens an overlay and provides dismiss function', function () { - expect(overlayService.createOverlay).toHaveBeenCalledWith( - 'vista.sessionSelectorView', - { - dismiss: jasmine.any(Function) - } - ); - }); + beforeEach(function () { + controller.selectSession(); + }); - it('passes method to dismiss overlay to overlay', function () { - var options = overlayService.createOverlay.calls.all()[0].args[1]; - expect(overlay.dismiss).not.toHaveBeenCalled(); - options.dismiss(); - expect(overlay.dismiss).toHaveBeenCalled(); - }); + it('opens an overlay and provides dismiss function', function () { + expect(overlayService.createOverlay).toHaveBeenCalledWith( + 'vista.sessionSelectorView', + { + dismiss: jasmine.any(Function) + } + ); }); - it('can disconnect the active stream', function () { - controller.disconnect(); - expect(sessionService.setActiveTopicOrSession) - .toHaveBeenCalledWith(undefined); + it('passes method to dismiss overlay to overlay', function () { + var options = overlayService.createOverlay.calls.all()[0].args[1]; + expect(overlay.dismiss).not.toHaveBeenCalled(); + options.dismiss(); + expect(overlay.dismiss).toHaveBeenCalled(); }); }); + + it('can disconnect the active stream', function () { + controller.disconnect(); + expect(sessionService.setActiveTopicOrSession) + .toHaveBeenCalledWith(undefined); + }); }); diff --git a/src/services/session/test/controllers/SessionSelectorControllerSpec.js b/src/services/session/test/controllers/SessionSelectorControllerSpec.js index a94d796..7e813f5 100644 --- a/src/services/session/test/controllers/SessionSelectorControllerSpec.js +++ b/src/services/session/test/controllers/SessionSelectorControllerSpec.js @@ -1,281 +1,270 @@ -/*global define,describe,beforeEach,jasmine,Promise,it,expect,afterEach, - waitsFor,runs*/ +// import SessionSelectorController from '../SessionSelectorController'; + +// this would be better tested in an e2e test +xdescribe('SessionSelectorController', function () { + let $scope; + let sessionService; + let controller; + + beforeEach(function () { + $scope = jasmine.createSpyObj('$scope', ['$digest']); + $scope.ngModel = { + dismiss: jasmine.createSpy('dismiss') + }; + + sessionService = jasmine.createSpyObj( + 'sessionService', + [ + 'setActiveTopicOrSession', + 'isActiveTopic', + 'isActiveSession', + 'getTopicsWithSessions' + ] + ); + + sessionService.isActiveTopic.and.returnValue(false); + sessionService.isActiveSession.and.returnValue(false); + + sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([ + { + topic: 'AMPCS.a', + jms_subtopic: 'a', + sessions: [ + { + number: 1, + topic: 'AMPCS.a', + jms_subtopic: 'a', + }, + { + number: 2, + topic: 'AMPCS.a', + jms_subtopic: 'a', + } + ] + }, + { + topic: 'AMPCS.b', + jms_subtopic: 'b', + sessions: [] + } + ])); + }); -define([ - // '../../src/controllers/SessionSelectorController' -], function ( - // SessionSelectorController -) { - 'use strict'; + describe('instantiation', function () { + beforeEach(function () { + controller = new SessionSelectorController($scope, sessionService); + }); - xdescribe('SessionSelectorController', function () { - var $scope, - sessionService, - controller; + it('sets scope variables', function () { + expect($scope.selection).toBeUndefined(); + expect($scope.topics.length).toBe(0); + }); - beforeEach(function () { - $scope = jasmine.createSpyObj('$scope', ['$digest']); - $scope.ngModel = { - dismiss: jasmine.createSpy('dismiss') - }; + it('immediately starts loading sessions', function () { + expect($scope.loading).toBe(true); + expect(sessionService.getTopicsWithSessions).toHaveBeenCalled(); + }); + }); - sessionService = jasmine.createSpyObj( - 'sessionService', - [ - 'setActiveTopicOrSession', - 'isActiveTopic', - 'isActiveSession', - 'getTopicsWithSessions' - ] - ); + describe('after loading', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + controller = new SessionSelectorController($scope, sessionService); + }); - sessionService.isActiveTopic.and.returnValue(false); - sessionService.isActiveSession.and.returnValue(false); + it('is no longer loading', function () { + expect($scope.loading).toBe(false); + }); - sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([ - { + it('has populated topics', function () { + expect($scope.topics.length).toBe(2); + expect($scope.topics).toContain({ + selected: false, + expanded: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', - sessions: [ - { - number: 1, + sessions: jasmine.any(Array) + }, + sessions: [ + { + selected: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', - }, - { - number: 2, + number: 1 + } + }, + { + selected: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', + number: 2 } - ] - }, - { + } + ] + }); + + expect($scope.topics).toContain({ + selected: false, + expanded: false, + data: { topic: 'AMPCS.b', jms_subtopic: 'b', sessions: [] - } - ])); - }); - - describe('instantiation', function () { - beforeEach(function () { - controller = new SessionSelectorController($scope, sessionService); - }); - - it('sets scope variables', function () { - expect($scope.selection).toBeUndefined(); - expect($scope.topics.length).toBe(0); - }); - - it('immediately starts loading sessions', function () { - expect($scope.loading).toBe(true); - expect(sessionService.getTopicsWithSessions).toHaveBeenCalled(); + }, + sessions: [] }); }); - describe('after loading', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('is no longer loading', function () { - expect($scope.loading).toBe(false); - }); + it('does not have a selection', function () { + expect($scope.selection).toBeUndefined(); + }); + }); - it('has populated topics', function () { - expect($scope.topics.length).toBe(2); - expect($scope.topics).toContain({ - selected: false, - expanded: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - sessions: jasmine.any(Array) - }, - sessions: [ - { - selected: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 1 - } - }, - { - selected: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 2 - } - } - ] + describe('loading with selected topic', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + sessionService + .isActiveTopic + .and.callFake(function (model) { + return model.topic === 'AMPCS.b' && !model.number; }); + controller = new SessionSelectorController($scope, sessionService); + }); - expect($scope.topics).toContain({ - selected: false, - expanded: false, - data: { - topic: 'AMPCS.b', - jms_subtopic: 'b', - sessions: [] - }, + it('has a selection', function () { + expect($scope.selection).toBeDefined(); + expect($scope.selection).toEqual({ + selected: true, + expanded: false, + data: { + topic: 'AMPCS.b', + jms_subtopic: 'b', sessions: [] - }); - }); - - it('does not have a selection', function () { - expect($scope.selection).toBeUndefined(); + }, + sessions: [] }); + expect($scope.selection).toBe($scope.topics[1]); }); + }); - describe('loading with selected topic', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - sessionService - .isActiveTopic - .and.callFake(function (model) { - return model.topic === 'AMPCS.b' && !model.number; - }); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('has a selection', function () { - expect($scope.selection).toBeDefined(); - expect($scope.selection).toEqual({ - selected: true, - expanded: false, - data: { - topic: 'AMPCS.b', - jms_subtopic: 'b', - sessions: [] - }, - sessions: [] + describe('loading with selected session', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + sessionService + .isActiveSession + .and.callFake(function (model) { + return model.topic === 'AMPCS.a' && + model.number === 2; }); - expect($scope.selection).toBe($scope.topics[1]); - }); + controller = new SessionSelectorController($scope, sessionService); }); - describe('loading with selected session', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - sessionService - .isActiveSession - .and.callFake(function (model) { - return model.topic === 'AMPCS.a' && - model.number === 2; - }); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('has a selection', function () { - expect($scope.selection).toBeDefined(); - expect($scope.selection).toEqual({ - selected: true, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 2 - } - }); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); + it('has a selection', function () { + expect($scope.selection).toBeDefined(); + expect($scope.selection).toEqual({ + selected: true, + data: { + topic: 'AMPCS.a', + jms_subtopic: 'a', + number: 2 + } }); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + }); - it('expands the containing topic', function () { - expect($scope.topics[0].expanded).toBe(true); - }); + it('expands the containing topic', function () { + expect($scope.topics[0].expanded).toBe(true); }); + }); - describe('selecting a session', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(() => { - controller.select($scope.topics[0].sessions[0]); - done(); - }); - controller = new SessionSelectorController($scope, sessionService); + describe('selecting a session', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(() => { + controller.select($scope.topics[0].sessions[0]); + done(); }); + controller = new SessionSelectorController($scope, sessionService); + }); - it('marks the session as selected', function () { - expect($scope.selection).toBe($scope.topics[0].sessions[0]); - expect($scope.selection.selected).toBe(true); - }); + it('marks the session as selected', function () { + expect($scope.selection).toBe($scope.topics[0].sessions[0]); + expect($scope.selection.selected).toBe(true); + }); - it('deselects when selecting a different session', function () { - controller.select($scope.topics[0].sessions[1]); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].sessions[0].selected).toBe(false); - }); + it('deselects when selecting a different session', function () { + controller.select($scope.topics[0].sessions[1]); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].sessions[0].selected).toBe(false); + }); - it('deselects when selecting a topic', function () { - controller.select($scope.topics[0]); - expect($scope.selection).toBe($scope.topics[0]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].sessions[0].selected).toBe(false); - }); + it('deselects when selecting a topic', function () { + controller.select($scope.topics[0]); + expect($scope.selection).toBe($scope.topics[0]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].sessions[0].selected).toBe(false); + }); - it('changes active topic when confirmed', function () { - controller.confirm(); - expect(sessionService.setActiveTopicOrSession) - .toHaveBeenCalledWith($scope.selection.data); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('changes active topic when confirmed', function () { + controller.confirm(); + expect(sessionService.setActiveTopicOrSession) + .toHaveBeenCalledWith($scope.selection.data); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); + }); - it('does not change active topic when canceled', function () { - controller.cancel(); - expect(sessionService.setActiveTopicOrSession) - .not - .toHaveBeenCalled(); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('does not change active topic when canceled', function () { + controller.cancel(); + expect(sessionService.setActiveTopicOrSession) + .not + .toHaveBeenCalled(); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); }); + }); - describe('selecting a topic', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(() => { - controller.select($scope.topics[0]); - done(); - }); - controller = new SessionSelectorController($scope, sessionService); + describe('selecting a topic', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(() => { + controller.select($scope.topics[0]); + done(); }); + controller = new SessionSelectorController($scope, sessionService); + }); - it('marks the topic as selected', function () { - expect($scope.selection).toBe($scope.topics[0]); - expect($scope.selection.selected).toBe(true); - }); + it('marks the topic as selected', function () { + expect($scope.selection).toBe($scope.topics[0]); + expect($scope.selection.selected).toBe(true); + }); - it('deselects when selecting a different session', function () { - controller.select($scope.topics[0].sessions[1]); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].selected).toBe(false); - }); + it('deselects when selecting a different session', function () { + controller.select($scope.topics[0].sessions[1]); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].selected).toBe(false); + }); - it('deselects when selecting a different topic', function () { - controller.select($scope.topics[1]); - expect($scope.selection).toBe($scope.topics[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].selected).toBe(false); - }); + it('deselects when selecting a different topic', function () { + controller.select($scope.topics[1]); + expect($scope.selection).toBe($scope.topics[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].selected).toBe(false); + }); - it('changes active topic when confirmed', function () { - controller.confirm(); - expect(sessionService.setActiveTopicOrSession) - .toHaveBeenCalledWith($scope.selection.data); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('changes active topic when confirmed', function () { + controller.confirm(); + expect(sessionService.setActiveTopicOrSession) + .toHaveBeenCalledWith($scope.selection.data); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); + }); - it('does not change active topic when canceled', function () { - controller.cancel(); - expect(sessionService.setActiveTopicOrSession) - .not - .toHaveBeenCalled(); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('does not change active topic when canceled', function () { + controller.cancel(); + expect(sessionService.setActiveTopicOrSession) + .not + .toHaveBeenCalled(); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); }); }); }); - -/* Sample promise for controller functionality */ - diff --git a/src/venues/VenueSpec.js b/src/venues/VenueSpec.js index 3eb5d28..126866f 100644 --- a/src/venues/VenueSpec.js +++ b/src/venues/VenueSpec.js @@ -1,94 +1,99 @@ -define([ - './Venue' -], function( - Venue -) { +import SessionService from 'services/session/SessionService'; +import Venue from './Venue'; - xdescribe('Venue', function () { - var configuration; - var sessionService; - var openmct; - var venue; +describe('Venue', () => { + let configuration; + let sessionService; + let venue; + let openmct; - beforeEach(function () { - configuration = { - "name": "EXAMPLE A", - "host": "host", - "prefix": "some prefix", - "mcwsRootUrl": "/mcws", - "channelDictionaryUrl": "/qdb/ChannelDictionary", - "channelEnumerationDictionaryUrl": "/qdb/ChannelEnumerationDictionary", - "channelHistoricalUrl": "/qdb/Channel", - "channelMinMaxUrl": "/lom/ChannelMinMax", - "channelLADUrl": "/lad/Channel", - "channelStreamUrl": "wss://host/mcws/stream/Channel", - "sessionUrl": "/qdb/Session", - "sessionLADUrl": "/lad/Session", - "eventRecordDictionaryUrl": "/qdb/EventRecordDictionary", - "evrHistoricalUrl": "/qdb/EventRecord", - "evrStreamUrl": "wss://host/mcws/stream/EventRecord", - "dataProductUrl": "/qdb/DataProduct", - "dataProductContentUrl": "/qdb/DataProductContent", - "dataProductStreamUrl": "wss://host/mcws/stream/DataProduct", - "packetUrl": "/qdb/Packet", - "packetContentUrl": "/qdb/PacketContent", - "packetSummaryEventStreamUrl": "wss://host/mcws/stream/PacketSummaryEvent", - "commandEventUrl": "/qdb/CommandEvent", - "commandEventStreamUrl": "wss://host/mcws/stream/CommandEvent" - }; - openmct = { - $injector: jasmine.createSpyObj('$injector', ['get']) - }; - sessionService = jasmine.createSpyObj('sessionService', [ - 'getActiveSessions' - ]); - openmct.$injector.get.and.callFake(function (dependency) { - expect(dependency).toBe('vista.sessions'); - return sessionService; - }); - venue = new Venue(configuration, openmct); + beforeEach(() => { + configuration = { + "name": "EXAMPLE A", + "host": "host", + "prefix": "some prefix", + "mcwsRootUrl": "/mcws", + "channelDictionaryUrl": "/qdb/ChannelDictionary", + "channelEnumerationDictionaryUrl": "/qdb/ChannelEnumerationDictionary", + "channelHistoricalUrl": "/qdb/Channel", + "channelMinMaxUrl": "/lom/ChannelMinMax", + "channelLADUrl": "/lad/Channel", + "channelStreamUrl": "wss://host/mcws/stream/Channel", + "sessionUrl": "/qdb/Session", + "sessionLADUrl": "/lad/Session", + "eventRecordDictionaryUrl": "/qdb/EventRecordDictionary", + "evrHistoricalUrl": "/qdb/EventRecord", + "evrStreamUrl": "wss://host/mcws/stream/EventRecord", + "dataProductUrl": "/qdb/DataProduct", + "dataProductContentUrl": "/qdb/DataProductContent", + "dataProductStreamUrl": "wss://host/mcws/stream/DataProduct", + "packetUrl": "/qdb/Packet", + "packetContentUrl": "/qdb/PacketContent", + "packetSummaryEventStreamUrl": "wss://host/mcws/stream/PacketSummaryEvent", + "commandEventUrl": "/qdb/CommandEvent", + "commandEventStreamUrl": "wss://host/mcws/stream/CommandEvent" + }; + openmct = jasmine.createSpyObj('openmct', [ + 'on' + ]); + openmct.on.and.returnValue(Promise.resolve()); + sessionService = new SessionService(openmct, { + sessions: { + historicalSessionFilter: { + disable: false, + maxRecords: 1000 + }, + realtimeSession: { + disable: false + } + } }); + sessionService = jasmine.createSpyObj('sessionService', [ + 'getActiveSessions' + ]); + venue = new Venue(configuration); + venue.sessionService = sessionService; + }); - it('has a host', function () { - expect(venue.host).toBe('host'); - }); + it('has a host', () => { + expect(venue.host).toBe(configuration.host); + }); - it('returns a model', function () { - var model = venue.getModel(); - expect(model.name).toBe('EXAMPLE A Dataset'); - expect(model.host).not.toBeDefined(); - expect(model.prefix).toBe("some prefix"); - expect(model.mcwsRootUrl).toBe("/mcws"); - expect(model.channelDictionaryUrl).toBe("/qdb/ChannelDictionary"); - expect(model.channelEnumerationDictionaryUrl).toBe("/qdb/ChannelEnumerationDictionary"); - expect(model.channelHistoricalUrl).toBe("/qdb/Channel"); - expect(model.channelMinMaxUrl).toBe("/lom/ChannelMinMax"); - expect(model.channelLADUrl).toBe("/lad/Channel"); - expect(model.channelStreamUrl).toBe("wss://host/mcws/stream/Channel"); - expect(model.sessionUrl).toBe("/qdb/Session"); - expect(model.sessionLADUrl).toBe("/lad/Session"); - expect(model.eventRecordDictionaryUrl).toBe("/qdb/EventRecordDictionary"); - expect(model.evrHistoricalUrl).toBe("/qdb/EventRecord"); - expect(model.evrStreamUrl).toBe("wss://host/mcws/stream/EventRecord"); - expect(model.dataProductUrl).toBe("/qdb/DataProduct"); - expect(model.dataProductContentUrl).toBe("/qdb/DataProductContent"); - expect(model.dataProductStreamUrl).toBe("wss://host/mcws/stream/DataProduct"); - expect(model.packetUrl).toBe("/qdb/Packet"); - expect(model.packetContentUrl).toBe("/qdb/PacketContent"); - expect(model.packetSummaryEventStreamUrl).toBe("wss://host/mcws/stream/PacketSummaryEvent"); - expect(model.commandEventUrl).toBe("/qdb/CommandEvent"); - expect(model.commandEventStreamUrl).toBe("wss://host/mcws/stream/CommandEvent"); - }); + it('returns a domain object', () => { + const domainObject = venue.getdomainObject(); + expect(domainObject.name).toBe(`${configuration.name} Dataset`); + expect(domainObject.host).not.toBeDefined(); + expect(domainObject.prefix).toBe(configuration.prefix); + expect(domainObject.mcwsRootUrl).toBe(configuration.mcwsRootUrl); + expect(domainObject.channelDictionaryUrl).toBe(configuration.channelDictionaryUrl); + expect(domainObject.channelEnumerationDictionaryUrl).toBe(configuration.channelEnumerationDictionaryUrl); + expect(domainObject.channelHistoricalUrl).toBe(configuration.channelHistoricalUrl); + expect(domainObject.channelMinMaxUrl).toBe(configuration.channelMinMaxUrl); + expect(domainObject.channelLADUrl).toBe(configuration.channelLADUrl); + expect(domainObject.channelStreamUrl).toBe(configuration.channelStreamUrl); + expect(domainObject.sessionUrl).toBe(configuration.sessionUrl); + expect(domainObject.sessionLADUrl).toBe(configuration.sessionLADUrl); + expect(domainObject.eventRecordDictionaryUrl).toBe(configuration.eventRecordDictionaryUrl); + expect(domainObject.evrHistoricalUrl).toBe(configuration.evrHistoricalUrl); + expect(domainObject.evrStreamUrl).toBe(configuration.evrStreamUrl); + expect(domainObject.dataProductUrl).toBe(configuration.dataProductUrl); + expect(domainObject.dataProductContentUrl).toBe(configuration.dataProductContentUrl); + expect(domainObject.dataProductStreamUrl).toBe(configuration.dataProductStreamUrl); + expect(domainObject.packetUrl).toBe(configuration.packetUrl); + expect(domainObject.packetContentUrl).toBe(configuration.packetContentUrl); + expect(domainObject.packetSummaryEventStreamUrl).toBe(configuration.packetSummaryEventStreamUrl); + expect(domainObject.commandEventUrl).toBe(configuration.commandEventUrl); + expect(domainObject.commandEventStreamUrl).toBe(configuration.commandEventStreamUrl); + }); - it('allows realtime', function () { - expect(venue.allowsRealtime()).toBe(true); - }); + it('allows realtime', () => { + expect(venue.allowsRealtime()).toBe(true); + }); - it('can get active sessions', function () { - var sessionResponse = {}; - sessionService.getActiveSessions.and.returnValue(sessionResponse); - var sessions = venue.getActiveSessions(); - expect(sessions).toBe(sessionResponse); - }); + it('can get active sessions', () => { + const sessionResponse = {}; + sessionService.getActiveSessions.and.returnValue(sessionResponse); + const sessions = venue.getActiveSessions(); + expect(sessions).toBe(sessionResponse); }); });