Skip to content

Commit

Permalink
feat(ui): add test for postman import v2
Browse files Browse the repository at this point in the history
  • Loading branch information
flawiddsouza committed Sep 6, 2024
1 parent 64226da commit aca019b
Show file tree
Hide file tree
Showing 4 changed files with 1,926 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/ui/src/parsers/postman.spec.ts
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)
})
Loading

0 comments on commit aca019b

Please sign in to comment.