-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(functions): normalizeFunction expects a Promise (#8468)
72af6cc introduced a bug when refactoring that calling `normalizeFunction` always returned a Promise. When it was removed, some calls to `normalizeFunction` may return plain objects that aren't wrapped in a Promise. Fix: wrap the return value with a `$q` to satisfy `IPromise`
- Loading branch information
Showing
3 changed files
with
228 additions
and
16 deletions.
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
app/scripts/modules/core/src/function/function.read.service.spec.ts
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 |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { API, FunctionReader, IFunctionSourceData } from 'core'; | ||
import { mock } from 'angular'; | ||
import { IFunctionTransformer } from 'core/function/function.transformer'; | ||
|
||
describe('FunctionReadService', () => { | ||
let $http: ng.IHttpBackendService; | ||
const functionTransformerMock: IFunctionTransformer = { | ||
normalizeFunction: (data): IFunctionSourceData => { | ||
return data; | ||
}, | ||
normalizeFunctionSet: (data): IFunctionSourceData[] => { | ||
return data; | ||
}, | ||
}; | ||
|
||
beforeEach( | ||
mock.inject(function($httpBackend: ng.IHttpBackendService) { | ||
$http = $httpBackend; | ||
}), | ||
); | ||
|
||
describe('loadFunctions', () => { | ||
it(`should set cloudprovider if not set`, done => { | ||
const functionReader = new FunctionReader(functionTransformerMock); | ||
|
||
$http.expectGET(`${API.baseUrl}/applications/app1/functions`).respond(200, [ | ||
{ | ||
name: 'account1', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
functionReader.loadFunctions('app1').then(data => { | ||
expect(data).toEqual([ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'aws', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'aws', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
done(); | ||
}); | ||
|
||
$http.flush(); | ||
}); | ||
|
||
it(`should not set cloudprovider if provided`, done => { | ||
const functionReader = new FunctionReader(functionTransformerMock); | ||
|
||
$http.expectGET(`${API.baseUrl}/applications/app1/functions`).respond(200, [ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
functionReader.loadFunctions('app1').then(data => { | ||
expect(data).toEqual([ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
done(); | ||
}); | ||
|
||
$http.flush(); | ||
}); | ||
}); | ||
|
||
describe('getFunctionDetails', () => { | ||
it(`should set cloudprovider if not set`, done => { | ||
const functionReader = new FunctionReader(functionTransformerMock); | ||
|
||
$http.whenGET(/.*\/functions\?.*/).respond((_method, _url, _data, _headers, params) => { | ||
expect(params).toEqual({ | ||
provider: 'aws', | ||
account: 'acct1', | ||
region: 'us-west-1', | ||
functionName: 'runner1', | ||
}); | ||
|
||
return [ | ||
200, | ||
[ | ||
{ | ||
name: 'account1', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
], | ||
]; | ||
}); | ||
|
||
functionReader.getFunctionDetails('aws', 'acct1', 'us-west-1', 'runner1').then(data => { | ||
expect(data).toEqual([ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'aws', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'aws', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
done(); | ||
}); | ||
|
||
$http.flush(); | ||
}); | ||
|
||
it(`should not set cloudprovider if provided`, done => { | ||
const functionReader = new FunctionReader(functionTransformerMock); | ||
|
||
$http.whenGET(/.*\/functions\?.*/).respond((_method, _url, _data, _headers, params) => { | ||
expect(params).toEqual({ | ||
provider: 'aws', | ||
account: 'acct1', | ||
region: 'us-west-1', | ||
functionName: 'runner1', | ||
}); | ||
|
||
return [ | ||
200, | ||
[ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
], | ||
]; | ||
}); | ||
|
||
functionReader.getFunctionDetails('aws', 'acct1', 'us-west-1', 'runner1').then(data => { | ||
expect(data).toEqual([ | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
{ | ||
name: 'account1', | ||
cloudProvider: 'fluffyCloud', | ||
provider: 'aws', | ||
type: 'aws', | ||
}, | ||
]); | ||
|
||
done(); | ||
}); | ||
|
||
$http.flush(); | ||
}); | ||
}); | ||
}); |
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
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