Created
November 18, 2015 20:21
-
-
Save squeedee/d2e49551ffc72c40e8d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| Pivnet.ReleaseAdmin.Actions.Async = {}; | |
| Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease = function(release) { | |
| Pivnet.ReleaseAdmin.Services.App.syncRelease(release.toJS()) | |
| .then(Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease.Completed); | |
| }; | |
| Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease.Completed = function(response) { | |
| var currentApp = Pivnet.ReleaseAdmin.Stores.App.get(); | |
| var appPrime = currentApp.mergeIn(['location', 'href'], response.body.location.href); | |
| Pivnet.ReleaseAdmin.Actions.App.hydrate(appPrime); | |
| }; | |
This file contains hidden or 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
| describe('Pivnet.ReleaseAdmin.Actions.Async', function() { | |
| describe('when a release is submitted', function() { | |
| var syncRelease; | |
| var servicePromise; | |
| var completedSpy; | |
| beforeEach(function() { | |
| servicePromise = jasmine.createSpyObj('servicePromise', ['then']); | |
| syncRelease = spyOn(Pivnet.ReleaseAdmin.Services.App, 'syncRelease').and.returnValue(servicePromise); | |
| completedSpy = spyOn(Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease, 'Completed'); | |
| }); | |
| it('creates a service promise', function() { | |
| var release = double('release'); | |
| var immutableRelease = Immutable.fromJS(release); | |
| Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease(immutableRelease); | |
| expect(syncRelease).toHaveBeenCalledWith(release); | |
| expect(servicePromise.then).toHaveBeenCalledWith(completedSpy); | |
| }); | |
| }); | |
| describe('when an release submission completes', function() { | |
| var hydrate; | |
| beforeEach(function() { | |
| hydrate = spyOn(Pivnet.ReleaseAdmin.Actions.App, 'hydrate'); | |
| var app = Immutable.fromJS({ | |
| release: 'Some Release', | |
| authenticityToken: 'abcd', | |
| location: {href: 'original-url'} | |
| }); | |
| spyOn(Pivnet.ReleaseAdmin.Stores.App, 'get').and.returnValue(app); | |
| }); | |
| it('calls hydrate with the mutated state', function() { | |
| Pivnet.ReleaseAdmin.Actions.Async.SubmitRelease.Completed({body: {location: {href: 'redirect-url'}}}); | |
| expect(hydrate).toHaveBeenCalled(); | |
| var hydratedWith = hydrate.calls.argsFor(0)[0]; | |
| expect(hydratedWith).toHaveDeepImmutableEqualityWith( | |
| Immutable.fromJS({ | |
| location: {href: 'redirect-url'}, | |
| release: 'Some Release', | |
| authenticityToken: 'abcd' | |
| }) | |
| ); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment