-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unit Tests] Update unit tests #256
Merged
+1,359
−1,303
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bfddfa
upddated 2 persistence test suites
jvigliotta ccf2e8c
removing debug code
jvigliotta f317dcb
updating more persistence tests
jvigliotta f7988c3
note session indicator is better tested in e2e
jvigliotta 4cc412e
note session selector test is better done with e2e now
jvigliotta a1d4dd2
updated venue unit test
jvigliotta d57d80a
removing unused variable
jvigliotta 0c85231
fixing some lint issues
jvigliotta b3e7a37
address pr comments, add back in lost code for product rows and for p…
jvigliotta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
340 changes: 224 additions & 116 deletions
340
src/persistence/test/MCWSNamespaceModelProviderSpec.js
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,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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use the defined path
'services/mcws/mcws'