Skip to content

Commit 3426530

Browse files
committed
feat: add more tests
1 parent 325c0fa commit 3426530

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

tests/pilot.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ const v3_expectedResult = {
5757
},
5858
}
5959

60+
const v2_expectedResult = {
61+
__pilot: {
62+
last_migrated: 0,
63+
version: 2,
64+
},
65+
66+
user: {
67+
id: 1,
68+
email: '',
69+
name: 'Random User',
70+
},
71+
}
72+
6073
test('should migrate from version 1 to version 2', (t) => {
6174
const source: MigrateSource = {
6275
name: 'John Doe',
@@ -158,3 +171,77 @@ test('should take a non-pilot object and upgrade it to version 3', (t) => {
158171

159172
t.deepEqual(actualResult, v3_expectedResult)
160173
})
174+
175+
test('should stop at version 2 if requested', (t) => {
176+
const source = {
177+
user: {
178+
id: 1,
179+
name: 'Random User',
180+
},
181+
}
182+
183+
const actualResult = migrate(source, v3_versions, {
184+
targetVersion: 2,
185+
})
186+
187+
// For the sake of simplicity, we're not testing the last_migrated property
188+
actualResult.__pilot.last_migrated = 0
189+
190+
t.deepEqual(actualResult, v2_expectedResult)
191+
})
192+
193+
test('should not migrate if the source is already at the target version', (t) => {
194+
const source = {
195+
__pilot: {
196+
version: 3,
197+
last_migrated: 0,
198+
},
199+
}
200+
201+
const actualResult = migrate(source, v3_versions)
202+
203+
t.deepEqual(actualResult, source)
204+
})
205+
206+
test('should not migrate if the source is already at the target version (with target version)', (t) => {
207+
const source = {
208+
__pilot: {
209+
version: 3,
210+
last_migrated: 0,
211+
},
212+
}
213+
214+
const actualResult = migrate(source, v3_versions, {
215+
targetVersion: 3,
216+
})
217+
218+
t.deepEqual(actualResult, source)
219+
})
220+
221+
test('should not migrate if the source version is higher than the target version', (t) => {
222+
const source = {
223+
__pilot: {
224+
version: 4,
225+
last_migrated: 0,
226+
},
227+
}
228+
229+
const actualResult = migrate(source, v3_versions)
230+
231+
t.deepEqual(actualResult, source)
232+
})
233+
234+
test('should not migrate if the source version is higher than the target version (with target version)', (t) => {
235+
const source = {
236+
__pilot: {
237+
version: 4,
238+
last_migrated: 0,
239+
},
240+
}
241+
242+
const actualResult = migrate(source, v3_versions, {
243+
targetVersion: 2,
244+
})
245+
246+
t.deepEqual(actualResult, source)
247+
})

0 commit comments

Comments
 (0)