Skip to content

Commit 217ad02

Browse files
committed
fix: return correct data when using select field
1 parent 9b20635 commit 217ad02

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/ipdata.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ export default class IPData {
176176

177177
try {
178178
const response = await axios.get(url, { params });
179-
const data = { ...response.data, status: response.status };
179+
let data = { ...response.data, status: response.status };
180+
181+
if (selectField) {
182+
data = { [selectField]: response.data, status: response.status };
183+
}
180184

181185
if ((!selectField || !fields) && this.useCache) {
182186
cache.set(ip || DEFAULT_IP, data);

test/ipdata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ describe('lookup()', () => {
6969
await expect(ipdata.lookup(null, field)).rejects.toThrowError(`${field} is not a valid field.`);
7070
});
7171

72-
it('should return a response with only the field', async () => {
72+
it.only('should return a response with only the field', async () => {
7373
const field = 'is_eu';
7474
const info = await ipdata.lookup(null, field);
75-
expect(info).toHaveProperty('select_field', false);
75+
expect(info).toHaveProperty(field, false);
7676
expect(info).toHaveProperty('status');
7777
});
7878
});

0 commit comments

Comments
 (0)