Skip to content

Commit 03bc875

Browse files
authored
feat(test): add some additional checks to help llamas (#1696)
* feat(test): add some additional checks to help llamas * feat(test): add some additional checks to help llamas * feat(test): remove duplicate datatype check on tvl * feat(test): reduce comment ambiguity
1 parent 1b6891a commit 03bc875

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/adaptors/test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,49 @@ describe(`Running ${process.env.npm_config_adapter} Test`, () => {
136136
protocolsSlug.includes(apy[0].project) && apy[0].project === adapter
137137
).toBe(true);
138138
});
139+
140+
describe('Check additional field data rules', () => {
141+
142+
// All fields added here are treated as optional
143+
// If a field is present, it will be checked against its rules
144+
let additionalFieldRules = {
145+
totalSupplyUsd: {
146+
type: 'number',
147+
},
148+
totalBorrowUsd: {
149+
type: 'number',
150+
},
151+
ltv: {
152+
min: 0,
153+
max: 1,
154+
},
155+
}
156+
157+
apy.forEach((pool) => {
158+
Object.entries(additionalFieldRules).map(([field, rule]) => {
159+
console.log({'pool[field]': pool[field]})
160+
if(pool[field] !== undefined) {
161+
if(rule.type !== undefined) {
162+
test(`${field} field of pool with id ${pool.pool} should be a ${rule.type}`, () => {
163+
expect(typeof pool[field]).toBe(rule.type);
164+
});
165+
}
166+
if((rule.max !== undefined) && (rule.min !== undefined)) {
167+
test(`${field} field of pool with id ${pool.pool} should be in the range of ${rule.min}-${rule.max}`, () => {
168+
expect(pool[field]).toBeLessThanOrEqual(rule.max);
169+
});
170+
} else if((rule.min !== undefined) && (rule.max === undefined)) {
171+
test(`${field} field of pool with id ${pool.pool} should be greater than or equal to ${rule.min}`, () => {
172+
expect(pool[field]).toBeGreaterThanOrEqual(rule.min);
173+
});
174+
} else if((rule.max !== undefined) && (rule.min === undefined)) {
175+
test(`${field} field of pool with id ${pool.pool} should be less than or equal to ${rule.max}`, () => {
176+
expect(pool[field]).toBeLessThanOrEqual(rule.max);
177+
});
178+
}
179+
}
180+
});
181+
});
182+
})
183+
139184
});

0 commit comments

Comments
 (0)