Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/petite-parents-win.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/generic-api-adapter': patch
---

Require ripcord field to be present when configured
3 changes: 1 addition & 2 deletions packages/sources/generic-api/src/transport/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const createMultiResponse = (
// Check ripcord
if (
param.ripcordPath !== undefined &&
objectPath.has(response.data, param.ripcordPath) &&
objectPath.get(response.data, param.ripcordPath).toString() !== param.ripcordDisabledValue
String(objectPath.get(response.data, param.ripcordPath)) !== param.ripcordDisabledValue
Comment thread
dskloetc marked this conversation as resolved.
) {
// Look for ripcordDetails as sibling field
const ripcordDetailsPath = `${param.ripcordPath}Details`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ exports[`execute http endpoint should return success 1`] = `
{
"data": {
"result": "123000",
"ripcord": false,
"ripcordAsInt": 0,
},
"result": "123000",
"statusCode": 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('execute', () => {
endpoint: 'http',
apiName: 'test',
dataPath: 'PoR',
ripcordPath: 'ripcord',
}
mockResponseSuccess()
const response = await testAdapter.request(data)
Expand Down
84 changes: 77 additions & 7 deletions packages/sources/generic-api/test/unit/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('GenericApiHttpTransport', () => {
const params = makeStub('params', {
apiName,
dataPath,
ripcordPath,
ripcordPath: undefined,
ripcordDisabledValue: 'false',
providerIndicatedTimePath: undefined,
})
Expand All @@ -199,8 +199,6 @@ describe('GenericApiHttpTransport', () => {
const expectedResponse = {
data: {
result: expectedValue,
ripcord: false,
ripcordAsInt: 0,
},
result: expectedValue,
timestamps: {
Expand Down Expand Up @@ -333,7 +331,7 @@ describe('GenericApiHttpTransport', () => {
const params = makeStub('params', {
apiName,
dataPath,
ripcordPath,
ripcordPath: undefined,
ripcordDisabledValue: 'false',
providerIndicatedTimePath: undefined,
})
Expand All @@ -353,8 +351,6 @@ describe('GenericApiHttpTransport', () => {
const expectedResponse = {
data: {
result: expectedValue,
ripcord: false,
ripcordAsInt: 0,
},
result: expectedValue,
timestamps: {
Expand All @@ -380,7 +376,7 @@ describe('GenericApiHttpTransport', () => {
const params = makeStub('params', {
apiName,
dataPath,
ripcordPath,
ripcordPath: undefined,
ripcordDisabledValue: 'false',
providerIndicatedTimePath: undefined,
})
Expand Down Expand Up @@ -736,6 +732,44 @@ describe('GenericApiHttpTransport', () => {
})
})

it('should treat missing ripcord as success with undefined disabledValue', async () => {
process.env.TEST_API_URL = apiUrl

const params = {
apiName,
dataPath: 'net_asset_value',
ripcordPath: 'ripcord',
ripcordDisabledValue: 'undefined',
}

const response = {
response: {
data: {
net_asset_value: 1.004373,
},
cost: undefined,
},
timestamps: {},
}

const expectedResponse = {
data: {
result: '1.004373',
ripcord: false,
ripcordAsInt: 0,
},
result: '1.004373',
timestamps: { providerIndicatedTimeUnixMs: undefined },
}

await doTransportTest({
params,
expectedRequestConfig: requestConfigWithoutAuthHeader,
response,
expectedResponse,
})
})

it('should not include ripcord status when ripcord path is absent', async () => {
process.env.TEST_API_URL = apiUrl

Expand Down Expand Up @@ -771,4 +805,40 @@ describe('GenericApiHttpTransport', () => {
expectedResponse,
})
})

it('should treat ripcord as enabled if ripcord field is expected but missing', async () => {
process.env.TEST_API_URL = apiUrl

const params = {
apiName,
dataPath: 'net_asset_value',
ripcordPath,
ripcordDisabledValue: 'false',
}

const response = {
response: {
data: {
net_asset_value: 1.004373,
},
cost: undefined,
},
timestamps: {},
}

const expectedResponse = {
errorMessage: `Ripcord activated for 'test'`,
ripcord: true,
ripcordAsInt: 1,
statusCode: 503,
timestamps: {},
}

await doTransportTest({
params,
expectedRequestConfig: requestConfigWithoutAuthHeader,
response,
expectedResponse,
})
})
})
Loading