Skip to content

Commit

Permalink
fix: infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 30, 2023
1 parent 012d866 commit 98409cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ module.exports =
let offset = 0
let items = []
let page
let pageIndex = -1

do {
page = await paginate(offset)
++pageIndex
items = uniqBy(items.concat(page.items), 'VIN')
offset = items.length
} while (page.items.length > 0)
} while ((pageIndex !== 0 || page.items.length >= ITEMS_PER_PAGE) && page.items.length > 0)

debug.info({ inventory, ...opts, items: items.length, duration: duration() })

Expand Down
3 changes: 3 additions & 0 deletions src/prices/ae.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ICC00": 8100,
"ICW00": 8100,
"IN3BW": 4500,
"INB3W": 6000,
"INBCW": 6000,
"INBPC": 6000,
"INPW0": 4500,
Expand All @@ -24,6 +25,7 @@
"MT325": 92000,
"MT328": 100000,
"MT337": 69000,
"MTS05": 26000,
"MTS13": 33000,
"MTS14": 88000,
"MTX04": 70000,
Expand All @@ -49,6 +51,7 @@
"WS12": 16500,
"WTSC": 8100,
"WTSD": 8100,
"WTTC": 18100,
"WTUT": 22200,
"WX20": 20100,
"WX21": 20100,
Expand Down
2 changes: 2 additions & 0 deletions src/prices/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"IPW0": 13000,
"IPW1": 13000,
"IPW2": 13000,
"IPW3": 13000,
"IWC00": 28200,
"IWW00": 28200,
"MT10A": 88000,
Expand All @@ -49,6 +50,7 @@
"MT340": 203990,
"MT341": 190000,
"MT351": 160000,
"MT352": 250000,
"MT85A": 88000,
"MT90A": 88000,
"MTS03": 88000,
Expand Down
11 changes: 10 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test('Model Y used', async t => {
t.true(results.every(item => item.Model === 'my'))
})

test('Model Y used (china)', async t => {
test('Model Y used (China)', async t => {
const results = await teslaInventory('cn', {
condition: 'used',
model: 'y'
Expand All @@ -123,3 +123,12 @@ test('Model Y new', async t => {

t.true(results.every(item => item.Model === 'my'))
})

test('Model Y new (Puerto Rico)', async t => {
const results = await teslaInventory('pr', {
condition: 'new',
model: 'y'
})

t.true(results.every(item => item.Model === 'my'))
})

0 comments on commit 98409cf

Please sign in to comment.