Lint, ES6, popover for codegen
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import feeds from "../feeds"
|
||||
import { shallowMount } from "@vue/test-utils"
|
||||
|
||||
jest.mock("~/helpers/fb", () => {
|
||||
return {
|
||||
jest.mock("~/helpers/fb", () => ({
|
||||
__esModule: true,
|
||||
|
||||
fb: {
|
||||
currentFeeds: [
|
||||
{
|
||||
@@ -25,10 +25,9 @@ jest.mock("~/helpers/fb", () => {
|
||||
],
|
||||
deleteFeed: jest.fn(() => Promise.resolve()),
|
||||
},
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
const { fb } = require("~/helpers/fb")
|
||||
import { fb } from "~/helpers/fb"
|
||||
|
||||
const factory = () =>
|
||||
shallowMount(feeds, {
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import inputform from "../inputform"
|
||||
import { shallowMount } from "@vue/test-utils"
|
||||
|
||||
jest.mock("~/helpers/fb", () => {
|
||||
return {
|
||||
jest.mock("~/helpers/fb", () => ({
|
||||
__esModule: true,
|
||||
|
||||
fb: {
|
||||
writeFeeds: jest.fn(() => Promise.resolve()),
|
||||
},
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
const { fb } = require("~/helpers/fb")
|
||||
import { fb } from "~/helpers/fb"
|
||||
|
||||
const factory = () =>
|
||||
shallowMount(inputform, {
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import logout from "../logout"
|
||||
import { shallowMount, createLocalVue } from "@vue/test-utils"
|
||||
|
||||
jest.mock("~/helpers/fb", () => {
|
||||
return {
|
||||
jest.mock("~/helpers/fb", () => ({
|
||||
__esModule: true,
|
||||
|
||||
fb: {
|
||||
signOutUser: jest.fn(() => Promise.resolve()),
|
||||
},
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
const { fb } = require("~/helpers/fb")
|
||||
import { fb } from "~/helpers/fb"
|
||||
|
||||
const $toast = {
|
||||
info: jest.fn(),
|
||||
|
||||
@@ -22,35 +22,39 @@ export const CsRestSharpCodegen = {
|
||||
|
||||
// initial request setup
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
requestBody = requestBody.replace(/"/g,'""'); // escape quotes for C# verbatim string compatibility
|
||||
requestBody = requestBody.replace(/"/g, '""') // escape quotes for C# verbatim string compatibility
|
||||
|
||||
// prepare data
|
||||
let requestDataFormat;
|
||||
let requestContentType;
|
||||
let requestDataFormat
|
||||
let requestContentType
|
||||
|
||||
if(isJSONContentType(contentType)) {
|
||||
requestDataFormat = 'DataFormat.Json'
|
||||
requestContentType = 'text/json'
|
||||
if (isJSONContentType(contentType)) {
|
||||
requestDataFormat = "DataFormat.Json"
|
||||
requestContentType = "text/json"
|
||||
} else {
|
||||
requestDataFormat = 'DataFormat.Xml'
|
||||
requestContentType = 'text/xml'
|
||||
requestDataFormat = "DataFormat.Xml"
|
||||
requestContentType = "text/xml"
|
||||
}
|
||||
|
||||
const verbs = [
|
||||
{ verb: 'GET', csMethod: 'Get' },
|
||||
{ verb: 'POST', csMethod: 'Post' },
|
||||
{ verb: 'PUT', csMethod: 'Put' },
|
||||
{ verb: 'PATCH', csMethod: 'Patch' },
|
||||
{ verb: 'DELETE', csMethod: 'Delete' },
|
||||
{ verb: "GET", csMethod: "Get" },
|
||||
{ verb: "POST", csMethod: "Post" },
|
||||
{ verb: "PUT", csMethod: "Put" },
|
||||
{ verb: "PATCH", csMethod: "Patch" },
|
||||
{ verb: "DELETE", csMethod: "Delete" },
|
||||
]
|
||||
|
||||
// create client and request
|
||||
requestString.push(`var client = new RestClient("${url}");\n\n`)
|
||||
requestString.push(`var request = new RestRequest("${pathName}${queryString}", ${requestDataFormat});\n\n`)
|
||||
requestString.push(
|
||||
`var request = new RestRequest("${pathName}${queryString}", ${requestDataFormat});\n\n`
|
||||
)
|
||||
|
||||
// authentification
|
||||
if (auth === "Basic Auth") {
|
||||
requestString.push(`client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`)
|
||||
requestString.push(
|
||||
`client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`
|
||||
)
|
||||
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
|
||||
requestString.push(`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`)
|
||||
}
|
||||
@@ -73,15 +77,19 @@ export const CsRestSharpCodegen = {
|
||||
|
||||
// set body
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
requestString.push(`request.AddParameter("${requestContentType}", @"${requestBody}", ParameterType.RequestBody);\n\n`)
|
||||
requestString.push(
|
||||
`request.AddParameter("${requestContentType}", @"${requestBody}", ParameterType.RequestBody);\n\n`
|
||||
)
|
||||
}
|
||||
|
||||
// process
|
||||
const verb = verbs.find(v => v.verb === method)
|
||||
const verb = verbs.find((v) => v.verb === method)
|
||||
requestString.push(`var response = client.${verb.csMethod}(request);\n\n`)
|
||||
|
||||
// analyse result
|
||||
requestString.push(`if (!response.IsSuccessful)\n{\n Console.WriteLine("An error occured " + response.ErrorMessage);\n}\n\n`)
|
||||
requestString.push(
|
||||
`if (!response.IsSuccessful)\n{\n Console.WriteLine("An error occured " + response.ErrorMessage);\n}\n\n`
|
||||
)
|
||||
|
||||
requestString.push(`var result = response.Content;\n`)
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export const NodeJsRequestCodegen = {
|
||||
reqBodyType = "body"
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
const formData = []
|
||||
if (requestBody.indexOf("=") > -1) {
|
||||
if (requestBody.includes("=")) {
|
||||
requestBody.split("&").forEach((rq) => {
|
||||
const [key, val] = rq.split("=")
|
||||
formData.push(`"${key}": "${val}"`)
|
||||
|
||||
@@ -56,7 +56,7 @@ export const PhpCurlCodegen = {
|
||||
} else if (isJSONContentType(contentType)) {
|
||||
requestBody = JSON.stringify(requestBody)
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
if (requestBody.indexOf("=") > -1) {
|
||||
if (requestBody.includes("=")) {
|
||||
requestBody = `"${requestBody}"`
|
||||
} else {
|
||||
const requestObject = JSON.parse(requestBody)
|
||||
|
||||
@@ -18,7 +18,7 @@ export const PowerShellRestMethod = {
|
||||
}) => {
|
||||
const methodsWithBody = ["Put", "Post", "Delete"]
|
||||
const formattedMethod = method[0].toUpperCase() + method.substring(1).toLowerCase()
|
||||
const includeBody = methodsWithBody.indexOf(formattedMethod) >= 0
|
||||
const includeBody = methodsWithBody.includes(formattedMethod)
|
||||
const requestString = []
|
||||
let genHeaders = []
|
||||
let variables = ""
|
||||
|
||||
@@ -72,7 +72,7 @@ export const PythonHttpClientCodegen = {
|
||||
requestString.push(`payload = ${requestBody}\n`)
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
const formData = []
|
||||
if (requestBody.indexOf("=") > -1) {
|
||||
if (requestBody.includes("=")) {
|
||||
requestBody.split("&").forEach((rq) => {
|
||||
const [key, val] = rq.split("=")
|
||||
formData.push(`('${key}', '${val}')`)
|
||||
|
||||
@@ -66,7 +66,7 @@ export const PythonRequestsCodegen = {
|
||||
requestString.push(`data = ${requestBody}\n`)
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
const formData = []
|
||||
if (requestBody.indexOf("=") > -1) {
|
||||
if (requestBody.includes("=")) {
|
||||
requestBody.split("&").forEach((rq) => {
|
||||
const [key, val] = rq.split("=")
|
||||
formData.push(`('${key}', '${val}')`)
|
||||
|
||||
@@ -17,7 +17,7 @@ export const ShellHTTPie = {
|
||||
headers,
|
||||
}) => {
|
||||
const methodsWithBody = ["POST", "PUT", "PATCH", "DELETE"]
|
||||
const includeBody = methodsWithBody.indexOf(method) >= 0
|
||||
const includeBody = methodsWithBody.includes(method)
|
||||
const requestString = []
|
||||
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
|
||||
@@ -309,7 +309,7 @@ export class FirebaseInstance {
|
||||
author: this.currentUser.uid,
|
||||
author_name: this.currentUser.displayName,
|
||||
author_image: this.currentUser.photoURL,
|
||||
team: team,
|
||||
team,
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -1043,11 +1043,23 @@
|
||||
<li>
|
||||
<label for="requestType">{{ $t("request_type") }}</label>
|
||||
<span class="select-wrapper">
|
||||
<select id="requestType" v-model="requestType">
|
||||
<option v-for="gen in codegens" :key="gen.id" :value="gen.id">
|
||||
<v-popover>
|
||||
<input
|
||||
id="requestType"
|
||||
v-model="requestType"
|
||||
:placeholder="$t('choose_language')"
|
||||
class="cursor-pointer"
|
||||
readonly
|
||||
autofocus
|
||||
/>
|
||||
<template slot="popover">
|
||||
<div v-for="gen in codegens" :key="gen.id">
|
||||
<button class="icon" @click="requestType = gen.id" v-close-popover>
|
||||
{{ gen.name }}
|
||||
</option>
|
||||
</select>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</v-popover>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user