|
|
@ -9,29 +9,25 @@ import { of } from 'rxjs'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
ContributorDto, |
|
|
|
|
|
ContributorsService, |
|
|
ContributorsService, |
|
|
ContributorsState, |
|
|
ContributorsState, |
|
|
DialogService, |
|
|
DialogService, |
|
|
versioned |
|
|
versioned |
|
|
} from '@app/shared/internal'; |
|
|
} from '@app/shared/internal'; |
|
|
|
|
|
|
|
|
|
|
|
import { createContributors } from '../services/contributors.service.spec'; |
|
|
|
|
|
|
|
|
import { TestValues } from './_test-helpers'; |
|
|
import { TestValues } from './_test-helpers'; |
|
|
|
|
|
|
|
|
describe('ContributorsState', () => { |
|
|
describe('ContributorsState', () => { |
|
|
const { |
|
|
const { |
|
|
app, |
|
|
app, |
|
|
appsState, |
|
|
appsState, |
|
|
authService, |
|
|
|
|
|
modifier, |
|
|
|
|
|
newVersion, |
|
|
newVersion, |
|
|
version |
|
|
version |
|
|
} = TestValues; |
|
|
} = TestValues; |
|
|
|
|
|
|
|
|
const oldContributors = [ |
|
|
const oldContributors = createContributors(1, 2, 3); |
|
|
new ContributorDto('id1', 'Developer'), |
|
|
|
|
|
new ContributorDto(modifier, 'Developer') |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
let dialogs: IMock<DialogService>; |
|
|
let dialogs: IMock<DialogService>; |
|
|
let contributorsService: IMock<ContributorsService>; |
|
|
let contributorsService: IMock<ContributorsService>; |
|
|
@ -41,7 +37,7 @@ describe('ContributorsState', () => { |
|
|
dialogs = Mock.ofType<DialogService>(); |
|
|
dialogs = Mock.ofType<DialogService>(); |
|
|
|
|
|
|
|
|
contributorsService = Mock.ofType<ContributorsService>(); |
|
|
contributorsService = Mock.ofType<ContributorsService>(); |
|
|
contributorsState = new ContributorsState(contributorsService.object, appsState.object, authService.object, dialogs.object); |
|
|
contributorsState = new ContributorsState(contributorsService.object, appsState.object, dialogs.object); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
afterEach(() => { |
|
|
afterEach(() => { |
|
|
@ -51,17 +47,14 @@ describe('ContributorsState', () => { |
|
|
describe('Loading', () => { |
|
|
describe('Loading', () => { |
|
|
it('should load contributors', () => { |
|
|
it('should load contributors', () => { |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
.returns(() => of(versioned(version, { contributors: oldContributors, maxContributors: 3 }))).verifiable(); |
|
|
.returns(() => of(versioned(version, oldContributors))).verifiable(); |
|
|
|
|
|
|
|
|
contributorsState.load().subscribe(); |
|
|
contributorsState.load().subscribe(); |
|
|
|
|
|
|
|
|
expect(contributorsState.snapshot.contributors.values).toEqual([ |
|
|
expect(contributorsState.snapshot.contributors.values).toEqual(oldContributors.contributors); |
|
|
{ isCurrentUser: false, contributor: oldContributors[0] }, |
|
|
|
|
|
{ isCurrentUser: true, contributor: oldContributors[1] } |
|
|
|
|
|
]); |
|
|
|
|
|
expect(contributorsState.snapshot.isMaxReached).toBeFalsy(); |
|
|
expect(contributorsState.snapshot.isMaxReached).toBeFalsy(); |
|
|
expect(contributorsState.snapshot.isLoaded).toBeTruthy(); |
|
|
expect(contributorsState.snapshot.isLoaded).toBeTruthy(); |
|
|
expect(contributorsState.snapshot.maxContributors).toBe(3); |
|
|
expect(contributorsState.snapshot.maxContributors).toBe(oldContributors.maxContributors); |
|
|
expect(contributorsState.snapshot.version).toEqual(version); |
|
|
expect(contributorsState.snapshot.version).toEqual(version); |
|
|
|
|
|
|
|
|
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never()); |
|
|
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never()); |
|
|
@ -69,7 +62,7 @@ describe('ContributorsState', () => { |
|
|
|
|
|
|
|
|
it('should show notification on load when reload is true', () => { |
|
|
it('should show notification on load when reload is true', () => { |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
.returns(() => of(versioned(version, { contributors: oldContributors, maxContributors: 3 }))).verifiable(); |
|
|
.returns(() => of(versioned(version, oldContributors))).verifiable(); |
|
|
|
|
|
|
|
|
contributorsState.load(true).subscribe(); |
|
|
contributorsState.load(true).subscribe(); |
|
|
|
|
|
|
|
|
@ -82,61 +75,36 @@ describe('ContributorsState', () => { |
|
|
describe('Updates', () => { |
|
|
describe('Updates', () => { |
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
contributorsService.setup(x => x.getContributors(app)) |
|
|
.returns(() => of(versioned(version, { contributors: oldContributors, maxContributors: 3 }))).verifiable(); |
|
|
.returns(() => of(versioned(version, oldContributors))).verifiable(); |
|
|
|
|
|
|
|
|
contributorsState.load().subscribe(); |
|
|
contributorsState.load().subscribe(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should add contributor to snapshot when assigned', () => { |
|
|
it('should update contributors when user assigned', () => { |
|
|
const newContributor = new ContributorDto('id3', 'Developer'); |
|
|
const updated = createContributors(1, 2, 3); |
|
|
|
|
|
|
|
|
const request = { contributorId: 'mail2stehle@gmail.com', role: newContributor.role }; |
|
|
const request = { contributorId: 'mail2stehle@gmail.com', role: 'Developer' }; |
|
|
const response = { contributorId: newContributor.contributorId, isCreated: true }; |
|
|
|
|
|
|
|
|
|
|
|
contributorsService.setup(x => x.postContributor(app, request, version)) |
|
|
contributorsService.setup(x => x.postContributor(app, request, version)) |
|
|
.returns(() => of(versioned(newVersion, response))).verifiable(); |
|
|
.returns(() => of(versioned(newVersion, updated))).verifiable(); |
|
|
|
|
|
|
|
|
contributorsState.assign(request).subscribe(); |
|
|
contributorsState.assign(request).subscribe(); |
|
|
|
|
|
|
|
|
expect(contributorsState.snapshot.contributors.values).toEqual([ |
|
|
expect(contributorsState.snapshot.contributors.values).toEqual(oldContributors.contributors); |
|
|
{ isCurrentUser: false, contributor: oldContributors[0] }, |
|
|
expect(contributorsState.snapshot.maxContributors).toBe(oldContributors.maxContributors); |
|
|
{ isCurrentUser: true, contributor: oldContributors[1] }, |
|
|
|
|
|
{ isCurrentUser: false, contributor: newContributor } |
|
|
|
|
|
]); |
|
|
|
|
|
expect(contributorsState.snapshot.isMaxReached).toBeTruthy(); |
|
|
|
|
|
expect(contributorsState.snapshot.maxContributors).toBe(3); |
|
|
|
|
|
expect(contributorsState.snapshot.version).toEqual(newVersion); |
|
|
expect(contributorsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should update contributor in snapshot when assigned and already added', () => { |
|
|
it('should update contributors when contribution revoked', () => { |
|
|
const newContributor = new ContributorDto(modifier, 'Owner'); |
|
|
const updated = createContributors(1, 2, 3); |
|
|
|
|
|
|
|
|
const request = { ...newContributor }; |
|
|
|
|
|
const response = { contributorId: newContributor.contributorId, isCreated: true }; |
|
|
|
|
|
|
|
|
|
|
|
contributorsService.setup(x => x.postContributor(app, request, version)) |
|
|
|
|
|
.returns(() => of(versioned(newVersion, response))).verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
contributorsState.assign(request).subscribe(); |
|
|
|
|
|
|
|
|
|
|
|
expect(contributorsState.snapshot.contributors.values).toEqual([ |
|
|
|
|
|
{ isCurrentUser: false, contributor: oldContributors[0] }, |
|
|
|
|
|
{ isCurrentUser: true, contributor: newContributor } |
|
|
|
|
|
]); |
|
|
|
|
|
expect(contributorsState.snapshot.isMaxReached).toBeFalsy(); |
|
|
|
|
|
expect(contributorsState.snapshot.maxContributors).toBe(3); |
|
|
|
|
|
expect(contributorsState.snapshot.version).toEqual(newVersion); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should remove contributor from snapshot when revoked', () => { |
|
|
contributorsService.setup(x => x.deleteContributor(app, oldContributors.contributors[0], version)) |
|
|
contributorsService.setup(x => x.deleteContributor(app, oldContributors[0].contributorId, version)) |
|
|
.returns(() => of(versioned(newVersion, updated))).verifiable(); |
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
contributorsState.revoke(oldContributors[0]).subscribe(); |
|
|
contributorsState.revoke(oldContributors.contributors[0]).subscribe(); |
|
|
|
|
|
|
|
|
expect(contributorsState.snapshot.contributors.values).toEqual([ |
|
|
expect(contributorsState.snapshot.contributors.values).toEqual(oldContributors.contributors); |
|
|
{ isCurrentUser: true, contributor: oldContributors[1] } |
|
|
expect(contributorsState.snapshot.maxContributors).toBe(oldContributors.maxContributors); |
|
|
]); |
|
|
|
|
|
expect(contributorsState.snapshot.version).toEqual(newVersion); |
|
|
expect(contributorsState.snapshot.version).toEqual(newVersion); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|