|
|
@ -9,13 +9,14 @@ import { of } from 'rxjs'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
ClientDto, |
|
|
|
|
|
ClientsService, |
|
|
ClientsService, |
|
|
ClientsState, |
|
|
ClientsState, |
|
|
DialogService, |
|
|
DialogService, |
|
|
versioned |
|
|
versioned |
|
|
} from '@app/shared/internal'; |
|
|
} from '@app/shared/internal'; |
|
|
|
|
|
|
|
|
|
|
|
import { createClients } from '../services/clients.service.spec'; |
|
|
|
|
|
|
|
|
import { TestValues } from './_test-helpers'; |
|
|
import { TestValues } from './_test-helpers'; |
|
|
|
|
|
|
|
|
describe('ClientsState', () => { |
|
|
describe('ClientsState', () => { |
|
|
@ -26,10 +27,7 @@ describe('ClientsState', () => { |
|
|
version |
|
|
version |
|
|
} = TestValues; |
|
|
} = TestValues; |
|
|
|
|
|
|
|
|
const oldClients = [ |
|
|
const oldClients = createClients(1, 2); |
|
|
new ClientDto('id1', 'name1', 'secret1'), |
|
|
|
|
|
new ClientDto('id2', 'name2', 'secret2') |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
let dialogs: IMock<DialogService>; |
|
|
let dialogs: IMock<DialogService>; |
|
|
let clientsService: IMock<ClientsService>; |
|
|
let clientsService: IMock<ClientsService>; |
|
|
@ -53,7 +51,7 @@ describe('ClientsState', () => { |
|
|
|
|
|
|
|
|
clientsState.load().subscribe(); |
|
|
clientsState.load().subscribe(); |
|
|
|
|
|
|
|
|
expect(clientsState.snapshot.clients.values).toEqual(oldClients); |
|
|
expect(clientsState.snapshot.clients.values).toEqual(oldClients.items); |
|
|
expect(clientsState.snapshot.version).toEqual(version); |
|
|
expect(clientsState.snapshot.version).toEqual(version); |
|
|
expect(clientsState.isLoaded).toBeTruthy(); |
|
|
expect(clientsState.isLoaded).toBeTruthy(); |
|
|
|
|
|
|
|
|
@ -80,21 +78,23 @@ describe('ClientsState', () => { |
|
|
clientsState.load().subscribe(); |
|
|
clientsState.load().subscribe(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should add client to snapshot when created', () => { |
|
|
it('should update clients when client added', () => { |
|
|
const newClient = new ClientDto('id3', 'name3', 'secret3'); |
|
|
const updated = createClients(1, 2, 3); |
|
|
|
|
|
|
|
|
const request = { id: 'id3' }; |
|
|
const request = { id: 'id3' }; |
|
|
|
|
|
|
|
|
clientsService.setup(x => x.postClient(app, request, version)) |
|
|
clientsService.setup(x => x.postClient(app, request, version)) |
|
|
.returns(() => of(versioned(newVersion, newClient))).verifiable(); |
|
|
.returns(() => of(versioned(newVersion, updated))).verifiable(); |
|
|
|
|
|
|
|
|
clientsState.attach(request).subscribe(); |
|
|
clientsState.attach(request).subscribe(); |
|
|
|
|
|
|
|
|
expect(clientsState.snapshot.clients.values).toEqual([...oldClients, newClient]); |
|
|
expect(clientsState.snapshot.clients.values).toEqual(updated.items); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should update properties when role updated', () => { |
|
|
it('should update clients when role updated', () => { |
|
|
|
|
|
const updated = createClients(1, 2, 3); |
|
|
|
|
|
|
|
|
const request = { role: 'Owner' }; |
|
|
const request = { role: 'Owner' }; |
|
|
|
|
|
|
|
|
clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version)) |
|
|
clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version)) |
|
|
@ -102,35 +102,33 @@ describe('ClientsState', () => { |
|
|
|
|
|
|
|
|
clientsState.update(oldClients[0], request).subscribe(); |
|
|
clientsState.update(oldClients[0], request).subscribe(); |
|
|
|
|
|
|
|
|
const client_1 = clientsState.snapshot.clients.at(0); |
|
|
expect(clientsState.snapshot.clients.values).toEqual(updated.items); |
|
|
|
|
|
|
|
|
expect(client_1.name).toBe('name1'); |
|
|
|
|
|
expect(client_1.role).toBe('Owner'); |
|
|
|
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should update properties when name updated', () => { |
|
|
it('should update clients when name updated', () => { |
|
|
|
|
|
const updated = createClients(1, 2, 3); |
|
|
|
|
|
|
|
|
const request = { name: 'NewName' }; |
|
|
const request = { name: 'NewName' }; |
|
|
|
|
|
|
|
|
clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version)) |
|
|
clientsService.setup(x => x.putClient(app, oldClients.items[0], request, version)) |
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
|
clientsState.update(oldClients[0], request).subscribe(); |
|
|
clientsState.update(oldClients[0], request).subscribe(); |
|
|
|
|
|
|
|
|
const client_1 = clientsState.snapshot.clients.at(0); |
|
|
expect(clientsState.snapshot.clients.values).toEqual(updated.items); |
|
|
|
|
|
|
|
|
expect(client_1.name).toBe('NewName'); |
|
|
|
|
|
expect(client_1.role).toBe('Developer'); |
|
|
|
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should remove client from snapshot when revoked', () => { |
|
|
it('should update clients when client revoked', () => { |
|
|
clientsService.setup(x => x.deleteClient(app, oldClients[0].id, version)) |
|
|
const updated = createClients(1, 2, 3); |
|
|
|
|
|
|
|
|
|
|
|
clientsService.setup(x => x.deleteClient(app, oldClients.items[0], version)) |
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
|
clientsState.revoke(oldClients[0]).subscribe(); |
|
|
clientsState.revoke(oldClients[0]).subscribe(); |
|
|
|
|
|
|
|
|
expect(clientsState.snapshot.clients.values).toEqual([oldClients[1]]); |
|
|
expect(clientsState.snapshot.clients.values).toEqual(updated.items); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
expect(clientsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|