-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
134 lines (107 loc) · 2.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict'
const test = require('ava')
const { fetcher } = require('./util')
const teslaInventory = (inventory, opts) => require('tesla-inventory')(fetcher)(inventory, opts)
test('inventory identifier is mandatory', async t => {
const error = await t.throwsAsync(() => teslaInventory(), {
instanceOf: TypeError
})
t.is(error.message, 'Tesla inventory `undefined` not found!')
})
test('inventory should be valid', async t => {
const error = await t.throwsAsync(
() =>
teslaInventory('unicorn', {
condition: 'used',
model: 's'
}),
{
instanceOf: TypeError
}
)
t.is(error.message, 'Tesla inventory `unicorn` not found!')
})
test('ensure results are consistent', async t => {
{
const results = await teslaInventory('us', { condition: 'used', model: '3' })
t.true(results.every(item => item.Model === 'm3'))
const vins = results.map(item => item.VIN)
t.is(vins.length, [...new Set(vins)].length)
}
{
const results = await teslaInventory('pr', { condition: 'new', model: 's' })
t.true(results.every(item => item.Model === 'ms'))
const vins = results.map(item => item.VIN)
t.is(vins.length, [...new Set(vins)].length)
}
})
test('Model S used', async t => {
const results = await teslaInventory('us', {
condition: 'used',
model: 's'
})
t.true(results.every(item => item.Model === 'ms'))
})
test('Model S new', async t => {
const results = await teslaInventory('us', {
condition: 'new',
model: 's'
})
t.true(results.every(item => item.Model === 'ms'))
})
test('Model 3 used', async t => {
const results = await teslaInventory('us', {
condition: 'used',
model: '3'
})
t.true(results.every(item => item.Model === 'm3'))
})
test('Model 3 new', async t => {
const results = await teslaInventory('us', {
condition: 'new',
model: '3'
})
t.true(results.every(item => item.Model === 'm3'))
})
test('Model X used', async t => {
const results = await teslaInventory('us', {
condition: 'used',
model: 'x'
})
t.true(results.every(item => item.Model === 'mx'))
})
test('Model X new', async t => {
const results = await teslaInventory('us', {
condition: 'new',
model: 'x'
})
t.true(results.every(item => item.Model === 'mx'))
})
test('Model Y used', async t => {
const results = await teslaInventory('us', {
condition: 'used',
model: 'y'
})
t.true(results.every(item => item.Model === 'my'))
})
test('Model Y used (China)', async t => {
const results = await teslaInventory('cn', {
condition: 'used',
model: 'y'
})
t.true(results.every(item => item.Model === 'my'))
})
test('Model Y new', async t => {
const results = await teslaInventory('us', {
condition: 'new',
model: 'y'
})
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'))
})