curlparser.spec.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. // @ts-check
  2. // ^^^ Enables Type Checking by the TypeScript compiler
  3. import { makeRESTRequest, rawKeyValueEntriesToString } from "@hoppscotch/data"
  4. import { parseCurlToHoppRESTReq } from ".."
  5. const samples = [
  6. {
  7. command: `
  8. curl --request GET \
  9. --url https://echo.hoppscotch.io/ \
  10. --header 'content-type: application/x-www-form-urlencoded' \
  11. --data a=b \
  12. --data c=d
  13. `,
  14. response: makeRESTRequest({
  15. method: "GET",
  16. name: "Untitled request",
  17. endpoint: "https://echo.hoppscotch.io/",
  18. auth: { authType: "none", authActive: true },
  19. body: {
  20. contentType: "application/x-www-form-urlencoded",
  21. body: rawKeyValueEntriesToString([
  22. {
  23. active: true,
  24. key: "a",
  25. value: "b",
  26. },
  27. {
  28. active: true,
  29. key: "c",
  30. value: "d",
  31. },
  32. ]),
  33. },
  34. headers: [],
  35. params: [],
  36. preRequestScript: "",
  37. testScript: "",
  38. }),
  39. },
  40. {
  41. command: `
  42. curl 'http://avs:def@127.0.0.1:8000/api/admin/crm/brand/4'
  43. -X PUT
  44. -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0'
  45. -H 'Accept: application/json, text/plain, */*'
  46. -H 'Accept-Language: en'
  47. --compressed
  48. -H 'Content-Type: application/hal+json;charset=utf-8'
  49. -H 'Origin: http://localhost:3012'
  50. -H 'Connection: keep-alive'
  51. -H 'Referer: http://localhost:3012/crm/company/4'
  52. --data-raw '{"id":4,"crm_company_id":4,"industry_primary_id":2,"industry_head_id":2,"industry_body_id":2,"code":"01","barcode":"222010101","summary":"Healt-Seasoning-Basic-Hori-Kello","name":"Kellolaa","sub_code":"01","sub_name":"Hori","created_at":"2020-06-08 08:50:02","updated_at":"2020-06-08 08:50:02","company":4,"primary":{"id":2,"code":"2","name":"Healt","created_at":"2020-05-19 07:05:02","updated_at":"2020-05-19 07:09:28"},"head":{"id":2,"code":"2","name":"Seasoning","created_at":"2020-04-14 19:34:33","updated_at":"2020-04-14 19:34:33"},"body":{"id":2,"code":"2","name":"Basic","created_at":"2020-04-14 19:33:54","updated_at":"2020-04-14 19:33:54"},"contacts":[]}'
  53. `,
  54. response: makeRESTRequest({
  55. method: "PUT",
  56. name: "Untitled request",
  57. endpoint: "http://127.0.0.1:8000/api/admin/crm/brand/4",
  58. auth: {
  59. authType: "basic",
  60. authActive: true,
  61. username: "avs",
  62. password: "def",
  63. },
  64. body: {
  65. contentType: "application/hal+json",
  66. body: `{
  67. "id": 4,
  68. "crm_company_id": 4,
  69. "industry_primary_id": 2,
  70. "industry_head_id": 2,
  71. "industry_body_id": 2,
  72. "code": "01",
  73. "barcode": "222010101",
  74. "summary": "Healt-Seasoning-Basic-Hori-Kello",
  75. "name": "Kellolaa",
  76. "sub_code": "01",
  77. "sub_name": "Hori",
  78. "created_at": "2020-06-08 08:50:02",
  79. "updated_at": "2020-06-08 08:50:02",
  80. "company": 4,
  81. "primary": {
  82. "id": 2,
  83. "code": "2",
  84. "name": "Healt",
  85. "created_at": "2020-05-19 07:05:02",
  86. "updated_at": "2020-05-19 07:09:28"
  87. },
  88. "head": {
  89. "id": 2,
  90. "code": "2",
  91. "name": "Seasoning",
  92. "created_at": "2020-04-14 19:34:33",
  93. "updated_at": "2020-04-14 19:34:33"
  94. },
  95. "body": {
  96. "id": 2,
  97. "code": "2",
  98. "name": "Basic",
  99. "created_at": "2020-04-14 19:33:54",
  100. "updated_at": "2020-04-14 19:33:54"
  101. },
  102. "contacts": []
  103. }`,
  104. },
  105. headers: [
  106. {
  107. active: true,
  108. key: "User-Agent",
  109. value:
  110. "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0",
  111. },
  112. {
  113. active: true,
  114. key: "Accept",
  115. value: "application/json, text/plain, */*",
  116. },
  117. {
  118. active: true,
  119. key: "Accept-Language",
  120. value: "en",
  121. },
  122. {
  123. active: true,
  124. key: "Origin",
  125. value: "http://localhost:3012",
  126. },
  127. {
  128. active: true,
  129. key: "Connection",
  130. value: "keep-alive",
  131. },
  132. {
  133. active: true,
  134. key: "Referer",
  135. value: "http://localhost:3012/crm/company/4",
  136. },
  137. ],
  138. params: [],
  139. preRequestScript: "",
  140. testScript: "",
  141. }),
  142. },
  143. {
  144. command: `curl google.com`,
  145. response: makeRESTRequest({
  146. method: "GET",
  147. name: "Untitled request",
  148. endpoint: "https://google.com/",
  149. auth: { authType: "none", authActive: true },
  150. body: {
  151. contentType: null,
  152. body: null,
  153. },
  154. headers: [],
  155. params: [],
  156. preRequestScript: "",
  157. testScript: "",
  158. }),
  159. },
  160. {
  161. command: `curl -X POST -d '{"foo":"bar"}' http://localhost:1111/hello/world/?bar=baz&buzz`,
  162. response: makeRESTRequest({
  163. method: "POST",
  164. name: "Untitled request",
  165. endpoint: "http://localhost:1111/hello/world/?buzz",
  166. auth: { authType: "none", authActive: true },
  167. body: {
  168. contentType: "application/json",
  169. body: `{\n "foo": "bar"\n}`,
  170. },
  171. headers: [],
  172. params: [
  173. {
  174. active: true,
  175. key: "bar",
  176. value: "baz",
  177. },
  178. ],
  179. preRequestScript: "",
  180. testScript: "",
  181. }),
  182. },
  183. {
  184. command: `curl --get -d "tool=curl" -d "age=old" https://example.com`,
  185. response: makeRESTRequest({
  186. method: "GET",
  187. name: "Untitled request",
  188. endpoint: "https://example.com/",
  189. auth: { authType: "none", authActive: true },
  190. body: {
  191. contentType: null,
  192. body: null,
  193. },
  194. headers: [],
  195. params: [
  196. {
  197. active: true,
  198. key: "tool",
  199. value: "curl",
  200. },
  201. {
  202. active: true,
  203. key: "age",
  204. value: "old",
  205. },
  206. ],
  207. preRequestScript: "",
  208. testScript: "",
  209. }),
  210. },
  211. {
  212. command: `curl -F hello=hello2 -F hello3=@hello4.txt bing.com`,
  213. response: makeRESTRequest({
  214. method: "POST",
  215. name: "Untitled request",
  216. endpoint: "https://bing.com/",
  217. auth: { authType: "none", authActive: true },
  218. body: {
  219. contentType: "multipart/form-data",
  220. body: [
  221. {
  222. active: true,
  223. isFile: false,
  224. key: "hello",
  225. value: "hello2",
  226. },
  227. {
  228. active: true,
  229. isFile: false,
  230. key: "hello3",
  231. value: "",
  232. },
  233. ],
  234. },
  235. headers: [],
  236. params: [],
  237. preRequestScript: "",
  238. testScript: "",
  239. }),
  240. },
  241. {
  242. command:
  243. "curl -X GET localhost -H 'Accept: application/json' --user root:toor",
  244. response: makeRESTRequest({
  245. method: "GET",
  246. name: "Untitled request",
  247. endpoint: "http://localhost/",
  248. auth: {
  249. authType: "basic",
  250. authActive: true,
  251. username: "root",
  252. password: "toor",
  253. },
  254. body: {
  255. contentType: null,
  256. body: null,
  257. },
  258. params: [],
  259. headers: [
  260. {
  261. active: true,
  262. key: "Accept",
  263. value: "application/json",
  264. },
  265. ],
  266. preRequestScript: "",
  267. testScript: "",
  268. }),
  269. },
  270. {
  271. command:
  272. "curl -X GET localhost --header 'Authorization: Basic dXNlcjpwYXNz'",
  273. response: makeRESTRequest({
  274. method: "GET",
  275. name: "Untitled request",
  276. endpoint: "http://localhost/",
  277. auth: {
  278. authType: "basic",
  279. authActive: true,
  280. username: "user",
  281. password: "pass",
  282. },
  283. body: {
  284. contentType: null,
  285. body: null,
  286. },
  287. params: [],
  288. headers: [],
  289. preRequestScript: "",
  290. testScript: "",
  291. }),
  292. },
  293. {
  294. command:
  295. "curl -X GET localhost:9900 --header 'Authorization: Basic 77898dXNlcjpwYXNz'",
  296. response: makeRESTRequest({
  297. method: "GET",
  298. name: "Untitled request",
  299. endpoint: "http://localhost:9900/",
  300. auth: {
  301. authType: "none",
  302. authActive: true,
  303. },
  304. body: {
  305. contentType: null,
  306. body: null,
  307. },
  308. params: [],
  309. headers: [],
  310. preRequestScript: "",
  311. testScript: "",
  312. }),
  313. },
  314. {
  315. command:
  316. "curl -X GET localhost --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'",
  317. response: makeRESTRequest({
  318. method: "GET",
  319. name: "Untitled request",
  320. endpoint: "http://localhost/",
  321. auth: {
  322. authType: "bearer",
  323. authActive: true,
  324. token:
  325. "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  326. },
  327. body: {
  328. contentType: null,
  329. body: null,
  330. },
  331. params: [],
  332. headers: [],
  333. preRequestScript: "",
  334. testScript: "",
  335. }),
  336. },
  337. {
  338. command: `curl --get -I -d "tool=curl" -d "platform=hoppscotch" -d"io" https://hoppscotch.io`,
  339. response: makeRESTRequest({
  340. method: "HEAD",
  341. name: "Untitled request",
  342. endpoint: "https://hoppscotch.io/?io",
  343. auth: {
  344. authActive: true,
  345. authType: "none",
  346. },
  347. body: {
  348. contentType: null,
  349. body: null,
  350. },
  351. params: [
  352. {
  353. active: true,
  354. key: "tool",
  355. value: "curl",
  356. },
  357. {
  358. active: true,
  359. key: "platform",
  360. value: "hoppscotch",
  361. },
  362. ],
  363. headers: [],
  364. preRequestScript: "",
  365. testScript: "",
  366. }),
  367. },
  368. {
  369. command: `curl 'https://someshadywebsite.com/questionable/path/?and=params&so&stay=tuned&' \
  370. -H 'user-agent: Mozilla/5.0' \
  371. -H 'accept: text/html' \
  372. -H $'cookie: cookie-cookie' \
  373. --data $'------WebKitFormBoundaryj3oufpIISPa2DP7c\\r\\nContent-Disposition: form-data; name="EmailAddress"\\r\\n\\r\\ntest@test.com\\r\\n------WebKitFormBoundaryj3oufpIISPa2DP7c\\r\\nContent-Disposition: form-data; name="Entity"\\r\\n\\r\\n1\\r\\n------WebKitFormBoundaryj3oufpIISPa2DP7c--\\r\\n'`,
  374. response: makeRESTRequest({
  375. method: "POST",
  376. name: "Untitled request",
  377. endpoint: "https://someshadywebsite.com/questionable/path/?so",
  378. auth: {
  379. authActive: true,
  380. authType: "none",
  381. },
  382. body: {
  383. contentType: "multipart/form-data",
  384. body: [
  385. {
  386. active: true,
  387. isFile: false,
  388. key: "EmailAddress",
  389. value: "test@test.com",
  390. },
  391. {
  392. active: true,
  393. isFile: false,
  394. key: "Entity",
  395. value: "1",
  396. },
  397. ],
  398. },
  399. params: [
  400. {
  401. active: true,
  402. key: "and",
  403. value: "params",
  404. },
  405. {
  406. active: true,
  407. key: "stay",
  408. value: "tuned",
  409. },
  410. ],
  411. headers: [
  412. {
  413. active: true,
  414. key: "user-agent",
  415. value: "Mozilla/5.0",
  416. },
  417. {
  418. active: true,
  419. key: "accept",
  420. value: "text/html",
  421. },
  422. {
  423. active: true,
  424. key: "cookie",
  425. value: "cookie-cookie",
  426. },
  427. ],
  428. preRequestScript: "",
  429. testScript: "",
  430. }),
  431. },
  432. {
  433. command:
  434. "curl localhost -H 'content-type: multipart/form-data; boundary=------------------------d74496d66958873e' --data '-----------------------------d74496d66958873e\\r\\nContent-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\\r\\nContent-Type: text/plain\\r\\n\\r\\nHello World\\r\\n\\r\\n-----------------------------d74496d66958873e--\\r\\n'",
  435. response: makeRESTRequest({
  436. method: "POST",
  437. name: "Untitled request",
  438. endpoint: "http://localhost/",
  439. auth: {
  440. authActive: true,
  441. authType: "none",
  442. },
  443. body: {
  444. contentType: "multipart/form-data",
  445. body: [
  446. {
  447. active: true,
  448. isFile: false,
  449. key: "file",
  450. value: "",
  451. },
  452. ],
  453. },
  454. params: [],
  455. headers: [],
  456. preRequestScript: "",
  457. testScript: "",
  458. }),
  459. },
  460. {
  461. command: `curl 'https://hoppscotch.io/' \
  462. -H 'authority: hoppscotch.io' \
  463. -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"' \
  464. -H 'accept: */*' \
  465. -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36' \
  466. -H 'sec-ch-ua-platform: "Windows"' \
  467. -H 'accept-language: en-US,en;q=0.9,ml;q=0.8' \
  468. --compressed`,
  469. response: makeRESTRequest({
  470. method: "GET",
  471. name: "Untitled request",
  472. endpoint: "https://hoppscotch.io/",
  473. auth: { authType: "none", authActive: true },
  474. body: {
  475. contentType: null,
  476. body: null,
  477. },
  478. params: [],
  479. headers: [
  480. {
  481. active: true,
  482. key: "authority",
  483. value: "hoppscotch.io",
  484. },
  485. {
  486. active: true,
  487. key: "sec-ch-ua",
  488. value:
  489. '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"',
  490. },
  491. {
  492. active: true,
  493. key: "accept",
  494. value: "*/*",
  495. },
  496. {
  497. active: true,
  498. key: "user-agent",
  499. value:
  500. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
  501. },
  502. {
  503. active: true,
  504. key: "sec-ch-ua-platform",
  505. value: '"Windows"',
  506. },
  507. {
  508. active: true,
  509. key: "accept-language",
  510. value: "en-US,en;q=0.9,ml;q=0.8",
  511. },
  512. ],
  513. preRequestScript: "",
  514. testScript: "",
  515. }),
  516. },
  517. {
  518. command: `curl --request GET \
  519. --url 'https://echo.hoppscotch.io/?hello=there' \
  520. --header 'content-type: application/x-www-form-urlencoded' \
  521. --header 'something: other-thing' \
  522. --data a=b \
  523. --data c=d`,
  524. response: makeRESTRequest({
  525. method: "GET",
  526. name: "Untitled request",
  527. endpoint: "https://echo.hoppscotch.io/",
  528. auth: { authType: "none", authActive: true },
  529. body: {
  530. contentType: "application/x-www-form-urlencoded",
  531. body: rawKeyValueEntriesToString([
  532. {
  533. key: "a",
  534. value: "b",
  535. active: true,
  536. },
  537. {
  538. key: "c",
  539. value: "d",
  540. active: true,
  541. },
  542. ]),
  543. },
  544. params: [
  545. {
  546. active: true,
  547. key: "hello",
  548. value: "there",
  549. },
  550. ],
  551. headers: [
  552. {
  553. active: true,
  554. key: "something",
  555. value: "other-thing",
  556. },
  557. ],
  558. preRequestScript: "",
  559. testScript: "",
  560. }),
  561. },
  562. {
  563. command: `curl --request POST \
  564. --url 'https://echo.hoppscotch.io/?hello=there' \
  565. --header 'content-type: multipart/form-data' \
  566. --header 'something: other-thing' \
  567. --form a=b \
  568. --form c=d`,
  569. response: makeRESTRequest({
  570. name: "Untitled request",
  571. endpoint: "https://echo.hoppscotch.io/",
  572. method: "POST",
  573. auth: { authType: "none", authActive: true },
  574. headers: [
  575. {
  576. active: true,
  577. key: "something",
  578. value: "other-thing",
  579. },
  580. ],
  581. body: {
  582. contentType: "multipart/form-data",
  583. body: [
  584. {
  585. active: true,
  586. isFile: false,
  587. key: "a",
  588. value: "b",
  589. },
  590. {
  591. active: true,
  592. isFile: false,
  593. key: "c",
  594. value: "d",
  595. },
  596. ],
  597. },
  598. params: [
  599. {
  600. active: true,
  601. key: "hello",
  602. value: "there",
  603. },
  604. ],
  605. preRequestScript: "",
  606. testScript: "",
  607. }),
  608. },
  609. {
  610. command: "curl 'muxueqz.top/skybook.html'",
  611. response: makeRESTRequest({
  612. name: "Untitled request",
  613. endpoint: "https://muxueqz.top/skybook.html",
  614. method: "GET",
  615. auth: { authType: "none", authActive: true },
  616. headers: [],
  617. body: { contentType: null, body: null },
  618. params: [],
  619. preRequestScript: "",
  620. testScript: "",
  621. }),
  622. },
  623. {
  624. command: "curl -F abcd=efghi",
  625. response: makeRESTRequest({
  626. name: "Untitled request",
  627. endpoint: "https://echo.hoppscotch.io/",
  628. method: "POST",
  629. auth: { authType: "none", authActive: true },
  630. headers: [],
  631. body: {
  632. contentType: "multipart/form-data",
  633. body: [
  634. {
  635. active: true,
  636. isFile: false,
  637. key: "abcd",
  638. value: "efghi",
  639. },
  640. ],
  641. },
  642. params: [],
  643. preRequestScript: "",
  644. testScript: "",
  645. }),
  646. },
  647. {
  648. command: "curl 127.0.0.1 -X custommethod",
  649. response: makeRESTRequest({
  650. name: "Untitled request",
  651. endpoint: "http://127.0.0.1/",
  652. method: "CUSTOMMETHOD",
  653. auth: { authType: "none", authActive: true },
  654. headers: [],
  655. body: {
  656. contentType: null,
  657. body: null,
  658. },
  659. params: [],
  660. preRequestScript: "",
  661. testScript: "",
  662. }),
  663. },
  664. {
  665. command: "curl echo.hoppscotch.io -A pinephone",
  666. response: makeRESTRequest({
  667. name: "Untitled request",
  668. endpoint: "https://echo.hoppscotch.io/",
  669. method: "GET",
  670. auth: { authType: "none", authActive: true },
  671. headers: [
  672. {
  673. active: true,
  674. key: "User-Agent",
  675. value: "pinephone",
  676. },
  677. ],
  678. body: {
  679. contentType: null,
  680. body: null,
  681. },
  682. params: [],
  683. preRequestScript: "",
  684. testScript: "",
  685. }),
  686. },
  687. {
  688. command: "curl echo.hoppscotch.io -G",
  689. response: makeRESTRequest({
  690. name: "Untitled request",
  691. endpoint: "https://echo.hoppscotch.io/",
  692. method: "GET",
  693. auth: { authType: "none", authActive: true },
  694. headers: [],
  695. body: {
  696. contentType: null,
  697. body: null,
  698. },
  699. params: [],
  700. preRequestScript: "",
  701. testScript: "",
  702. }),
  703. },
  704. {
  705. command: `curl --get -I -d "tool=hopp" https://example.org`,
  706. response: makeRESTRequest({
  707. name: "Untitled request",
  708. endpoint: "https://example.org/",
  709. method: "HEAD",
  710. auth: { authType: "none", authActive: true },
  711. headers: [],
  712. body: {
  713. contentType: null,
  714. body: null,
  715. },
  716. params: [
  717. {
  718. active: true,
  719. key: "tool",
  720. value: "hopp",
  721. },
  722. ],
  723. preRequestScript: "",
  724. testScript: "",
  725. }),
  726. },
  727. {
  728. command: `curl google.com -u userx`,
  729. response: makeRESTRequest({
  730. method: "GET",
  731. name: "Untitled request",
  732. endpoint: "https://google.com/",
  733. auth: {
  734. authType: "basic",
  735. authActive: true,
  736. username: "userx",
  737. password: "",
  738. },
  739. body: {
  740. contentType: null,
  741. body: null,
  742. },
  743. params: [],
  744. headers: [],
  745. preRequestScript: "",
  746. testScript: "",
  747. }),
  748. },
  749. {
  750. command: `curl google.com -H "Authorization"`,
  751. response: makeRESTRequest({
  752. method: "GET",
  753. name: "Untitled request",
  754. endpoint: "https://google.com/",
  755. auth: {
  756. authType: "none",
  757. authActive: true,
  758. },
  759. body: {
  760. contentType: null,
  761. body: null,
  762. },
  763. params: [],
  764. headers: [],
  765. preRequestScript: "",
  766. testScript: "",
  767. }),
  768. },
  769. {
  770. command: `curl \`
  771. google.com -H "content-type: application/json"`,
  772. response: makeRESTRequest({
  773. method: "GET",
  774. name: "Untitled request",
  775. endpoint: "https://google.com/",
  776. auth: {
  777. authType: "none",
  778. authActive: true,
  779. },
  780. body: {
  781. contentType: null,
  782. body: null,
  783. },
  784. params: [],
  785. headers: [],
  786. preRequestScript: "",
  787. testScript: "",
  788. }),
  789. },
  790. {
  791. command: `curl 192.168.0.24:8080/ping`,
  792. response: makeRESTRequest({
  793. method: "GET",
  794. name: "Untitled request",
  795. endpoint: "http://192.168.0.24:8080/ping",
  796. auth: {
  797. authType: "none",
  798. authActive: true,
  799. },
  800. body: {
  801. contentType: null,
  802. body: null,
  803. },
  804. params: [],
  805. headers: [],
  806. preRequestScript: "",
  807. testScript: "",
  808. }),
  809. },
  810. ]
  811. describe("Parse curl command to Hopp REST Request", () => {
  812. for (const [i, { command, response }] of samples.entries()) {
  813. test(`for sample #${i + 1}:\n\n${command}`, () => {
  814. expect(parseCurlToHoppRESTReq(command)).toEqual(response)
  815. })
  816. }
  817. })