Skip to content

Commit 7191dd0

Browse files
authored
Fix ripcord bug in generic-api (#4972)
1 parent 5224c0f commit 7191dd0

5 files changed

Lines changed: 83 additions & 12 deletions

File tree

.changeset/petite-parents-win.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/generic-api-adapter': patch
3+
---
4+
5+
Require ripcord field to be present when configured

packages/sources/generic-api/src/transport/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ const createMultiResponse = (
6060
// Check ripcord
6161
if (
6262
param.ripcordPath !== undefined &&
63-
objectPath.has(response.data, param.ripcordPath) &&
64-
objectPath.get(response.data, param.ripcordPath).toString() !== param.ripcordDisabledValue
63+
String(objectPath.get(response.data, param.ripcordPath)) !== param.ripcordDisabledValue
6564
) {
6665
// Look for ripcordDetails as sibling field
6766
const ripcordDetailsPath = `${param.ripcordPath}Details`

packages/sources/generic-api/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ exports[`execute http endpoint should return success 1`] = `
44
{
55
"data": {
66
"result": "123000",
7-
"ripcord": false,
8-
"ripcordAsInt": 0,
97
},
108
"result": "123000",
119
"statusCode": 200,

packages/sources/generic-api/test/integration/adapter.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('execute', () => {
5353
endpoint: 'http',
5454
apiName: 'test',
5555
dataPath: 'PoR',
56-
ripcordPath: 'ripcord',
5756
}
5857
mockResponseSuccess()
5958
const response = await testAdapter.request(data)

packages/sources/generic-api/test/unit/http.test.ts

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('GenericApiHttpTransport', () => {
179179
const params = makeStub('params', {
180180
apiName,
181181
dataPath,
182-
ripcordPath,
182+
ripcordPath: undefined,
183183
ripcordDisabledValue: 'false',
184184
providerIndicatedTimePath: undefined,
185185
})
@@ -199,8 +199,6 @@ describe('GenericApiHttpTransport', () => {
199199
const expectedResponse = {
200200
data: {
201201
result: expectedValue,
202-
ripcord: false,
203-
ripcordAsInt: 0,
204202
},
205203
result: expectedValue,
206204
timestamps: {
@@ -333,7 +331,7 @@ describe('GenericApiHttpTransport', () => {
333331
const params = makeStub('params', {
334332
apiName,
335333
dataPath,
336-
ripcordPath,
334+
ripcordPath: undefined,
337335
ripcordDisabledValue: 'false',
338336
providerIndicatedTimePath: undefined,
339337
})
@@ -353,8 +351,6 @@ describe('GenericApiHttpTransport', () => {
353351
const expectedResponse = {
354352
data: {
355353
result: expectedValue,
356-
ripcord: false,
357-
ripcordAsInt: 0,
358354
},
359355
result: expectedValue,
360356
timestamps: {
@@ -380,7 +376,7 @@ describe('GenericApiHttpTransport', () => {
380376
const params = makeStub('params', {
381377
apiName,
382378
dataPath,
383-
ripcordPath,
379+
ripcordPath: undefined,
384380
ripcordDisabledValue: 'false',
385381
providerIndicatedTimePath: undefined,
386382
})
@@ -736,6 +732,44 @@ describe('GenericApiHttpTransport', () => {
736732
})
737733
})
738734

735+
it('should treat missing ripcord as success with undefined disabledValue', async () => {
736+
process.env.TEST_API_URL = apiUrl
737+
738+
const params = {
739+
apiName,
740+
dataPath: 'net_asset_value',
741+
ripcordPath: 'ripcord',
742+
ripcordDisabledValue: 'undefined',
743+
}
744+
745+
const response = {
746+
response: {
747+
data: {
748+
net_asset_value: 1.004373,
749+
},
750+
cost: undefined,
751+
},
752+
timestamps: {},
753+
}
754+
755+
const expectedResponse = {
756+
data: {
757+
result: '1.004373',
758+
ripcord: false,
759+
ripcordAsInt: 0,
760+
},
761+
result: '1.004373',
762+
timestamps: { providerIndicatedTimeUnixMs: undefined },
763+
}
764+
765+
await doTransportTest({
766+
params,
767+
expectedRequestConfig: requestConfigWithoutAuthHeader,
768+
response,
769+
expectedResponse,
770+
})
771+
})
772+
739773
it('should not include ripcord status when ripcord path is absent', async () => {
740774
process.env.TEST_API_URL = apiUrl
741775

@@ -771,4 +805,40 @@ describe('GenericApiHttpTransport', () => {
771805
expectedResponse,
772806
})
773807
})
808+
809+
it('should treat ripcord as enabled if ripcord field is expected but missing', async () => {
810+
process.env.TEST_API_URL = apiUrl
811+
812+
const params = {
813+
apiName,
814+
dataPath: 'net_asset_value',
815+
ripcordPath,
816+
ripcordDisabledValue: 'false',
817+
}
818+
819+
const response = {
820+
response: {
821+
data: {
822+
net_asset_value: 1.004373,
823+
},
824+
cost: undefined,
825+
},
826+
timestamps: {},
827+
}
828+
829+
const expectedResponse = {
830+
errorMessage: `Ripcord activated for 'test'`,
831+
ripcord: true,
832+
ripcordAsInt: 1,
833+
statusCode: 503,
834+
timestamps: {},
835+
}
836+
837+
await doTransportTest({
838+
params,
839+
expectedRequestConfig: requestConfigWithoutAuthHeader,
840+
response,
841+
expectedResponse,
842+
})
843+
})
774844
})

0 commit comments

Comments
 (0)