-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add test for postman import v2
- Loading branch information
1 parent
64226da
commit aca019b
Showing
4 changed files
with
1,926 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { test, expect } from 'vitest' | ||
import { readFile, writeFile } from 'node:fs/promises' | ||
import path from 'node:path' | ||
import { convertPostmanExportToRestfoxCollection } from './postman' | ||
import { addSortOrderToTree, flattenTree } from '@/helpers' | ||
|
||
test('importPostmanV2', async() => { | ||
const currentFolder = path.dirname(new URL(import.meta.url).pathname) | ||
|
||
const testDataFolder = path.join(currentFolder, '..', '..', 'test-data', 'postman-import-v2') | ||
|
||
const inputFile = await readFile(path.join(testDataFolder, 'Argos.API.postman_collection.json'), 'utf-8') | ||
const input = JSON.parse(inputFile) | ||
const outputFile = await readFile(path.join(testDataFolder, 'Restfox_2024-09-06.json'), 'utf-8') | ||
const expected = JSON.parse(outputFile) | ||
|
||
const converted: any = await convertPostmanExportToRestfoxCollection(input, false, expected.collection[0].workspaceId) | ||
|
||
const collectionTree = converted.collection | ||
addSortOrderToTree(collectionTree) | ||
const collection: any[] = JSON.parse(JSON.stringify(flattenTree(collectionTree))) | ||
|
||
collection.sort((a, b) => { | ||
return a.name.localeCompare(b.name) | ||
}) | ||
|
||
collection.forEach((item) => { | ||
item.plugins = [] | ||
delete item._id | ||
delete item.parentId | ||
}) | ||
|
||
const expectedCollection: any[] = expected.collection | ||
|
||
expectedCollection.sort((a, b) => { | ||
return a.name.localeCompare(b.name) | ||
}) | ||
|
||
expectedCollection.forEach((item) => { | ||
delete item._id | ||
delete item.parentId | ||
}) | ||
|
||
writeFile(path.join(testDataFolder, 'test-snapshot.json'), JSON.stringify(collection, null, 2), 'utf-8') | ||
|
||
expect(collection).toEqual(expectedCollection) | ||
}) |
Oops, something went wrong.