From fe3bea31bd2dd25250a3703dc0d3ec7841ae70b2 Mon Sep 17 00:00:00 2001 From: Vidya Sagar <59490902+vidya-hub@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:21:37 +0530 Subject: [PATCH] rev: reverted changes in js code gen --- lib/codegen/js/axios.dart | 1 + lib/codegen/js/fetch.dart | 3 ++- test/codegen/js_fetch_codegen_test.dart | 18 ++++++++++++------ test/codegen/nodejs_axios_codegen_test.dart | 21 +++++++++++++++++++++ test/codegen/nodejs_fetch_codegen_test.dart | 18 ++++++++++++------ 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/codegen/js/axios.dart b/lib/codegen/js/axios.dart index ee826e32..1aeee285 100644 --- a/lib/codegen/js/axios.dart +++ b/lib/codegen/js/axios.dart @@ -11,6 +11,7 @@ class AxiosCodeGen { final bool isNodeJs; String kStringImportNode = """{% if isNodeJs %}import axios from 'axios'; + {% endif %}{% if isFormDataRequest and isNodeJs %}const fs = require('fs');{% endif %} """; diff --git a/lib/codegen/js/fetch.dart b/lib/codegen/js/fetch.dart index fb2b4e36..4ef2e551 100644 --- a/lib/codegen/js/fetch.dart +++ b/lib/codegen/js/fetch.dart @@ -27,7 +27,8 @@ let options = { """; String kTemplateBody = """, - body: {{body}} + body: +{{body}} """; String kMultiPartBodyTemplate = r''' diff --git a/test/codegen/js_fetch_codegen_test.dart b/test/codegen/js_fetch_codegen_test.dart index e7426bf1..43d053f9 100644 --- a/test/codegen/js_fetch_codegen_test.dart +++ b/test/codegen/js_fetch_codegen_test.dart @@ -398,7 +398,8 @@ let options = { headers: { "Content-Type": "text/plain" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -427,7 +428,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -457,7 +459,8 @@ let options = { "Content-Type": "application/json", "User-Agent": "Test Agent" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -488,7 +491,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}" + body: +"{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}" }; let status; @@ -519,7 +523,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" + body: +"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" }; let status; @@ -575,7 +580,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" + body: +"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" }; let status; diff --git a/test/codegen/nodejs_axios_codegen_test.dart b/test/codegen/nodejs_axios_codegen_test.dart index 974b410e..519f5ab5 100644 --- a/test/codegen/nodejs_axios_codegen_test.dart +++ b/test/codegen/nodejs_axios_codegen_test.dart @@ -8,6 +8,7 @@ void main() { group('GET Request', () { test('GET 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com', method: 'get' @@ -30,6 +31,7 @@ axios(config) test('GET 2', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/country/data', method: 'get', @@ -55,6 +57,7 @@ axios(config) test('GET 3', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/country/data', method: 'get', @@ -80,6 +83,7 @@ axios(config) test('GET 4', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/humanize/social', method: 'get', @@ -109,6 +113,7 @@ axios(config) test('GET 5', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.github.com/repos/foss42/apidash', method: 'get', @@ -134,6 +139,7 @@ axios(config) test('GET 6', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.github.com/repos/foss42/apidash', method: 'get', @@ -162,6 +168,7 @@ axios(config) test('GET 7', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com', method: 'get' @@ -184,6 +191,7 @@ axios(config) test('GET 8', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.github.com/repos/foss42/apidash', method: 'get', @@ -212,6 +220,7 @@ axios(config) test('GET 9', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/humanize/social', method: 'get', @@ -238,6 +247,7 @@ axios(config) test('GET 10', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/humanize/social', method: 'get', @@ -268,6 +278,7 @@ axios(config) test('GET 11', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/humanize/social', method: 'get', @@ -297,6 +308,7 @@ axios(config) test('GET 12', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/humanize/social', method: 'get' @@ -321,6 +333,7 @@ axios(config) group('HEAD Request', () { test('HEAD 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com', method: 'head' @@ -343,6 +356,7 @@ axios(config) test('HEAD 2', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'http://api.foss42.com', method: 'head' @@ -367,6 +381,7 @@ axios(config) group('POST Request', () { test('POST 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/case/lower', method: 'post', @@ -393,6 +408,7 @@ axios(config) test('POST 2', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/case/lower', method: 'post', @@ -419,6 +435,7 @@ axios(config) test('POST 3', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://api.foss42.com/case/lower', method: 'post', @@ -448,6 +465,7 @@ axios(config) group('PUT Request', () { test('PUT 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://reqres.in/api/users/2', method: 'put', @@ -476,6 +494,7 @@ axios(config) group('PATCH Request', () { test('PATCH 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://reqres.in/api/users/2', method: 'patch', @@ -504,6 +523,7 @@ axios(config) group('DELETE Request', () { test('DELETE 1', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://reqres.in/api/users/2', method: 'delete' @@ -526,6 +546,7 @@ axios(config) test('DELETE 2', () { const expectedCode = r"""import axios from 'axios'; + let config = { url: 'https://reqres.in/api/users/2', method: 'delete', diff --git a/test/codegen/nodejs_fetch_codegen_test.dart b/test/codegen/nodejs_fetch_codegen_test.dart index feca786d..c06ceee5 100644 --- a/test/codegen/nodejs_fetch_codegen_test.dart +++ b/test/codegen/nodejs_fetch_codegen_test.dart @@ -418,7 +418,8 @@ let options = { headers: { "Content-Type": "text/plain" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -449,7 +450,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -481,7 +483,8 @@ let options = { "Content-Type": "application/json", "User-Agent": "Test Agent" }, - body: "{\n\"text\": \"I LOVE Flutter\"\n}" + body: +"{\n\"text\": \"I LOVE Flutter\"\n}" }; let status; @@ -514,7 +517,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}" + body: +"{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}" }; let status; @@ -547,7 +551,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" + body: +"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" }; let status; @@ -607,7 +612,8 @@ let options = { headers: { "Content-Type": "application/json" }, - body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" + body: +"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}" }; let status;