Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/bruno-app/src/utils/importers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BrunoError } from 'utils/common/error';
import { isOpenApiSpec } from './openapi-collection';
import { isPostmanCollection } from './postman-collection';
import { isInsomniaCollection } from './insomnia-collection';
import { valueToString } from '@usebruno/common/utils';

export const validateSchema = async (collections = []) => {
collections = Array.isArray(collections) ? collections : [collections];
Expand Down Expand Up @@ -98,6 +99,7 @@ export const transformItemsInCollection = (collection) => {
item.type = `${item.type}-request`;
const isGrpcRequest = item.type === 'grpc-request';
const isWSRequest = item.type === 'ws-request';
item.request.url = valueToString(item.request.url);

if (item.request.query) {
item.request.params = item.request.query.map((queryItem) => ({
Expand Down Expand Up @@ -137,6 +139,10 @@ export const transformItemsInCollection = (collection) => {
const isGrpcExample = example.type === 'grpc-request';
const isWSExample = example.type === 'ws-request';

if (example.request) {
example.request.url = valueToString(example.request.url);
}

if (example.request && example.request.query) {
example.request.params = example.request.query.map((queryItem) => ({
...queryItem,
Expand Down
51 changes: 51 additions & 0 deletions tests/import/bruno/fixtures/bruno-grpc-request-missing-url.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "GRPC Collection",
"version": "1",
"items": [
{
"type": "grpc",
"name": "request without url",
"filename": "request-without-url.bru",
"seq": 2,
"settings": {},
"tags": [],
"examples": [],
"request": {
"method": "",
"headers": [],
"body": {
"mode": "grpc",
"formUrlEncoded": [],
"multipartForm": [],
"file": [],
"grpc": [
{
"name": "message 1",
"content": "{}"
}
]
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"docs": "",
"auth": {
"mode": "none"
}
}
}
],
"environments": [],
"brunoConfig": {
"version": "1",
"name": "GRPC Collection",
"type": "collection",
"ignore": [
"node_modules",
".git"
],
"size": 0,
"filesCount": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "HTTP Example Collection",
"version": "1",
"items": [
{
"type": "http",
"name": "request with example",
"filename": "request-with-example.bru",
"seq": 1,
"settings": {},
"tags": [],
"examples": [
{
"uid": "ex0011223344556677889",
"itemUid": "it0011223344556677889",
"name": "Successful response",
"description": "Example whose request has no url",
"type": "http",
"request": {
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "none"
}
},
"response": {
"status": 200,
"statusText": "OK",
"headers": [
{
"uid": "hd0011223344556677889",
"name": "content-type",
"value": "application/json",
"enabled": true
}
],
"body": {
"type": "json",
"content": "{\n \"message\": \"hello\"\n}"
}
}
}
],
"request": {
"method": "GET",
"headers": [],
"url": "",
"params": [],
"body": {
"mode": "none",
"json": null,
"text": null,
"xml": null,
"sparql": null,
"formUrlEncoded": [],
"multipartForm": [],
"file": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"docs": "",
"auth": {
"mode": "none"
}
}
}
],
"environments": [],
"brunoConfig": {
"version": "1",
"name": "HTTP Example Collection",
"type": "collection",
"ignore": [
"node_modules",
".git"
],
"size": 0,
"filesCount": 0
}
}
50 changes: 50 additions & 0 deletions tests/import/bruno/fixtures/bruno-http-request-missing-url.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "HTTP Collection",
"version": "1",
"items": [
{
"type": "http",
"name": "request without url",
"filename": "request-without-url.bru",
"seq": 2,
"settings": {},
"tags": [],
"examples": [],
Comment thread
sharan-bruno marked this conversation as resolved.
"request": {
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "none",
"json": null,
"text": null,
"xml": null,
"sparql": null,
"formUrlEncoded": [],
"multipartForm": [],
"file": []
},
"script": {},
"vars": {},
"assertions": [],
"tests": "",
"docs": "",
"auth": {
"mode": "none"
}
}
}
],
"environments": [],
"brunoConfig": {
"version": "1",
"name": "HTTP Collection",
"type": "collection",
"ignore": [
"node_modules",
".git"
],
"size": 0,
"filesCount": 0
}
}
31 changes: 31 additions & 0 deletions tests/import/bruno/import-bruno-request-missing-url.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect } from '../../../playwright';
import * as path from 'path';
import { importCollection, closeAllCollections, buildCommonLocators } from '../../utils/page';

test.describe.serial('Import Bruno Collection - request with missing URL', () => {
test.afterAll(async ({ page }) => {
await closeAllCollections(page);
});

const cases = [
{ fixture: 'bruno-http-request-missing-url.json', collectionName: 'HTTP Collection', type: 'HTTP' },
{ fixture: 'bruno-grpc-request-missing-url.json', collectionName: 'GRPC Collection', type: 'gRPC' },
{ fixture: 'bruno-http-example-request-missing-url.json', collectionName: 'HTTP Example Collection', type: 'HTTP example' }
];

for (const { fixture, collectionName, type } of cases) {
test(`imports a ${type} request without a URL`, async ({ page, createTmpDir }) => {
const brunoFile = path.resolve(__dirname, 'fixtures', fixture);
const location = await createTmpDir(collectionName);

await importCollection(page, brunoFile, location, {
expectedCollectionName: collectionName
});
});

test(`${type} collection appears in the sidebar after import`, async ({ page }) => {
const locators = buildCommonLocators(page);
await expect(locators.sidebar.collection(collectionName)).toBeVisible();
});
}
});
Comment thread
sharan-bruno marked this conversation as resolved.
Loading