feat: sample collection + bug fixes

This commit is contained in:
Anoop M D
2022-10-17 00:39:58 +05:30
parent 6573df41b0
commit 241ee5e788
15 changed files with 217 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import toast from 'react-hot-toast';
import { uuid } from 'utils/common';
import { collectionSchema } from '@usebruno/schema';
import { saveCollectionToIdb } from 'utils/idb';
import sampleCollection from './samples/sample-collection.json';
const readFile = (files) => {
return new Promise((resolve, reject) => {
@@ -83,4 +84,16 @@ const importCollection = () => {
});
};
export const importSampleCollection = () => {
return new Promise((resolve, reject) => {
validateSchema(sampleCollection)
.then(validateSchema)
.then(updateUidsInCollection)
.then(validateSchema)
.then((collection) => saveCollectionToIdb(window.__idb, collection))
.then(resolve)
.catch(reject);
});
};
export default importCollection;

View File

@@ -0,0 +1,129 @@
{
"name": "sample-collection",
"uid": "c1PdISj460OeNmFLI8rCY",
"version": "1",
"items": [
{
"uid": "myeFbgzNlwIhDpYcOVBWS",
"type": "http-request",
"name": "Users",
"request": {
"url": "https://reqres.in/api/users?page=2",
"method": "GET",
"headers": [],
"params": [
{
"uid": "viHGWSpAQhpiwH9UQxb7W",
"name": "page",
"value": "2",
"enabled": true
}
],
"body": {
"mode": "json",
"json": "",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
},
{
"uid": "ytzXIADbhEwLB0BqIQOKD",
"type": "http-request",
"name": "Single User",
"request": {
"url": "https://reqres.in/api/users/2",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
},
{
"uid": "DuEyHudhVuxrdplKLAMsU",
"type": "http-request",
"name": "User Not Found",
"request": {
"url": "https://reqres.in/api/users/23",
"method": "GET",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
},
{
"uid": "UZFjsr14q8iZ1Do90q02Q",
"type": "http-request",
"name": "Create",
"request": {
"url": "https://reqres.in/api/users",
"method": "POST",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"name\": \"morpheus\",\n \"job\": \"leader\"\n}",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
},
{
"uid": "lYLCTXaerD9etRDLJHbVN",
"type": "http-request",
"name": "Update",
"request": {
"url": "https://reqres.in/api/users/2",
"method": "PUT",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
},
{
"uid": "qVCKx5xUqxpBf8jeka8Gu",
"type": "http-request",
"name": "Remove",
"request": {
"url": "https://reqres.in/api/users/2",
"method": "DELETE",
"headers": [],
"params": [],
"body": {
"mode": "json",
"json": "{\n \"name\": \"morpheus\",\n \"job\": \"zion resident\"\n}",
"text": null,
"xml": null,
"formUrlEncoded": [],
"multipartForm": []
}
}
}
],
"environments": []
}

View File

@@ -25,6 +25,14 @@ export const sendHttpRequestInBrowser = async (request, options) => {
deleteCancelToken(options.cancelTokenUid);
}
if(error.response) {
return {
status: error.response.status,
headers: error.response.headers,
data: error.response.data
}
};
return Promise.reject(error);
}
};