|
1 | 1 | import { serviceToken } from '../token-accessor'; |
2 | 2 | import { resolveServiceBinding } from '../environment-accessor/service-bindings'; |
3 | 3 | import { decodeJwt } from '../jwt'; |
4 | | -import { transformServiceBindingToDestination } from './service-binding-to-destination'; |
| 4 | +import { |
| 5 | + transformServiceBindingToClientCredentialsDestination, |
| 6 | + transformServiceBindingToDestination |
| 7 | +} from './service-binding-to-destination'; |
5 | 8 |
|
6 | 9 | const services = { |
7 | 10 | destination: [ |
@@ -68,10 +71,10 @@ const services = { |
68 | 71 | name: 'some-service1', |
69 | 72 | label: 'some-service', |
70 | 73 | tags: ['some-service'], |
| 74 | + url: 'some-service-url', |
71 | 75 | credentials: { |
72 | 76 | clientid: 'some-service-clientid', |
73 | | - clientsecret: 'some-service-clientsecret', |
74 | | - uri: 'some-service-uri' |
| 77 | + clientsecret: 'some-service-clientsecret' |
75 | 78 | } |
76 | 79 | } |
77 | 80 | ], |
@@ -211,4 +214,45 @@ describe('service binding to destination', () => { |
211 | 214 | '"The provided service binding of type some-service is not supported out of the box for destination transformation."' |
212 | 215 | ); |
213 | 216 | }); |
| 217 | + |
| 218 | + it('transforms a generic service binding to a client credentials destination', async () => { |
| 219 | + const destination = |
| 220 | + await transformServiceBindingToClientCredentialsDestination( |
| 221 | + resolveServiceBinding('some-service') |
| 222 | + ); |
| 223 | + expect(destination).toEqual( |
| 224 | + expect.objectContaining({ |
| 225 | + url: 'some-service-url', |
| 226 | + name: 'some-service1', |
| 227 | + authentication: 'OAuth2ClientCredentials', |
| 228 | + authTokens: expect.arrayContaining([ |
| 229 | + expect.objectContaining({ |
| 230 | + value: 'access-token', |
| 231 | + type: 'bearer' |
| 232 | + }) |
| 233 | + ]) |
| 234 | + }) |
| 235 | + ); |
| 236 | + }); |
| 237 | + |
| 238 | + it('transforms a generic service binding to a client credentials destination with custom url', async () => { |
| 239 | + const destination = |
| 240 | + await transformServiceBindingToClientCredentialsDestination( |
| 241 | + resolveServiceBinding('some-service'), |
| 242 | + { url: 'some-custom-service-url' } |
| 243 | + ); |
| 244 | + expect(destination).toEqual( |
| 245 | + expect.objectContaining({ |
| 246 | + url: 'some-custom-service-url', |
| 247 | + name: 'some-service1', |
| 248 | + authentication: 'OAuth2ClientCredentials', |
| 249 | + authTokens: expect.arrayContaining([ |
| 250 | + expect.objectContaining({ |
| 251 | + value: 'access-token', |
| 252 | + type: 'bearer' |
| 253 | + }) |
| 254 | + ]) |
| 255 | + }) |
| 256 | + ); |
| 257 | + }); |
214 | 258 | }); |
0 commit comments