From 3edf0342a52cb6f311ce41aa756323d243385446 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 5 Nov 2024 18:49:51 -0500 Subject: [PATCH] Delete tests for deleted utils --- .../unit/utils/determine-body-promise-test.js | 60 ---- .../unit/utils/mung-options-for-fetch-test.js | 292 ------------------ 2 files changed, 352 deletions(-) delete mode 100644 test-app/tests/unit/utils/determine-body-promise-test.js delete mode 100644 test-app/tests/unit/utils/mung-options-for-fetch-test.js diff --git a/test-app/tests/unit/utils/determine-body-promise-test.js b/test-app/tests/unit/utils/determine-body-promise-test.js deleted file mode 100644 index 3554da1e..00000000 --- a/test-app/tests/unit/utils/determine-body-promise-test.js +++ /dev/null @@ -1,60 +0,0 @@ -import { module, test } from 'qunit'; -import { Response } from 'fetch'; -import determineBodyPromise from 'ember-fetch/utils/determine-body-promise'; - -module('Unit | determineBodyPromise', function() { - test('determineBodyResponse returns the body when it is present', function(assert) { - assert.expect(1); - - const response = new Response('{"data": "foo"}', { status: 200 }); - const bodyPromise = determineBodyPromise(response, {}); - - return bodyPromise.then(body => { - assert.deepEqual(body, { data: 'foo' }); - }); - }); - - test('determineBodyResponse returns the body even if it is not json', function(assert) { - assert.expect(1); - - const response = new Response('this is not json', { status: 200 }); - const bodyPromise = determineBodyPromise(response, {}); - - return bodyPromise.then(body => { - assert.deepEqual(body, 'this is not json'); - }); - }); - - test('determineBodyResponse returns undefined when the http status code is 204', function(assert) { - assert.expect(1); - - const response = new Response(null, { status: 204 }); - const bodyPromise = determineBodyPromise(response, {}); - - return bodyPromise.then(body => { - assert.deepEqual(body, undefined); - }); - }); - - test('determineBodyResponse returns undefined when the http status code is 205', function(assert) { - assert.expect(1); - - const response = new Response(null, { status: 205 }); - const bodyPromise = determineBodyPromise(response, {}); - - return bodyPromise.then(body => { - assert.deepEqual(body, undefined); - }); - }); - - test("determineBodyResponse returns undefined when the request method is 'HEAD'", function(assert) { - assert.expect(1); - - const response = new Response(null, { status: 200 }); - const bodyPromise = determineBodyPromise(response, { method: 'HEAD' }); - - return bodyPromise.then(body => { - assert.deepEqual(body, undefined); - }); - }); -}); diff --git a/test-app/tests/unit/utils/mung-options-for-fetch-test.js b/test-app/tests/unit/utils/mung-options-for-fetch-test.js deleted file mode 100644 index 8c4cc8b5..00000000 --- a/test-app/tests/unit/utils/mung-options-for-fetch-test.js +++ /dev/null @@ -1,292 +0,0 @@ -import { module, test } from 'qunit'; -import mungOptionsForFetch from 'ember-fetch/utils/mung-options-for-fetch'; - -module('Unit | mungOptionsForFetch', function() { - test('mungOptionsForFetch transforms jQuery-style options into fetch compatible options', function(assert) { - assert.expect(2); - - const jQueryGetOptions = { - url: 'https://emberjs.com', - type: 'GET', - headers: { - 'x-fake-header': 13, - 'Content-Type': 'application/vnd.api+json' - }, - data: { - a: 1, - b: 2 - } - }; - - const fetchGetOptions = mungOptionsForFetch(jQueryGetOptions); - - assert.deepEqual( - fetchGetOptions, - { - credentials: 'same-origin', - url: 'https://emberjs.com?a=1&b=2', - method: 'GET', - type: 'GET', - headers: { - 'x-fake-header': 13, - 'Content-Type': 'application/vnd.api+json' - }, - data: { - a: 1, - b: 2 - } - }, - "GET call's options are correct" - ); - - const jqueryPostOptions = { - url: 'https://emberjs.com', - type: 'POST', - data: { a: 1 } - }; - - const fetchPostOptions = mungOptionsForFetch(jqueryPostOptions); - assert.deepEqual( - fetchPostOptions, - { - credentials: 'same-origin', - url: 'https://emberjs.com', - method: 'POST', - type: 'POST', - body: '{"a":1}', - data: { - a: 1 - } - }, - "POST call's options are correct" - ); - }); - - test('mungOptionsForFetch sets the method to "GET" if `type` is not provided', function(assert) { - assert.expect(1); - const getOptions = { - url: 'https://emberjs.com', - type: undefined - }; - - const options = mungOptionsForFetch(getOptions); - assert.equal(options.method, 'GET'); - }); - - test('mungOptionsForFetch sets the method to an uppercase string', function(assert) { - assert.expect(2); - const getOptions = { - url: 'https://emberjs.com', - type: 'get', - }; - - let options = mungOptionsForFetch(getOptions); - assert.equal(options.method, 'GET'); - - const postOptions = { - url: 'https://emberjs.com', - method: 'post', - }; - - options = mungOptionsForFetch(postOptions); - assert.equal(options.method, 'POST'); - }); - - test('mungOptionsForFetch adds string query params to the url correctly', function(assert) { - assert.expect(2); - - const baseUrl = 'https://emberjs.com'; - const noQueryStringOptions = { - url: baseUrl, - data: { a: 1, b: 2 } - }; - - let options = mungOptionsForFetch(noQueryStringOptions); - assert.equal( - options.url, - `${baseUrl}?a=1&b=2`, - 'url that started without query params has query params' - ); - - const hasQueryStringOptions = { - url: `${baseUrl}?fastboot=true`, - data: { a: 1, b: 2 } - }; - - options = mungOptionsForFetch(hasQueryStringOptions); - assert.equal( - options.url, - `${baseUrl}?fastboot=true&a=1&b=2`, - 'url that started with query params has more query params' - ); - }); - - test("mungOptionsForFetch removes undefined query params when method is POST and 'data' is an object", function(assert) { - assert.expect(1); - - const dataAsObject = { - a: 1, - b: undefined, - c: 3, - d: null, - e: 0, - f: false - }; - - const undefinedQueryStringOptions = { - url: 'https://emberjs.com', - type: 'POST', - data: dataAsObject - }; - - let options = mungOptionsForFetch(undefinedQueryStringOptions); - assert.deepEqual(options.body, '{"a":1,"c":3,"d":null,"e":0,"f":false}'); - }); - - test('mungOptionsForFetch sets the request body correctly when the method is not GET or HEAD', function(assert) { - assert.expect(3); - - const baseOptions = { - url: '/', - type: 'POST', - data: { a: 1 } - }; - - // Tests POST method. - let options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - JSON.stringify(baseOptions.data), - 'POST request body correctly set' - ); - - // Tests PUT method. - baseOptions.type = 'PUT'; - options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - JSON.stringify(baseOptions.data), - 'PUT request body correctly set' - ); - - // Tests DELETE method. - baseOptions.type = 'DELETE'; - options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - JSON.stringify(baseOptions.data), - 'DELETE request has the correct body' - ); - }); - - test("mungOptionsForFetch sets the request body correctly when the method is POST and 'data' is a string", function(assert) { - assert.expect(1); - - // Tests stringified objects. - const stringifiedData = JSON.stringify({ a: 1, b: 2 }); - const optionsWithStringData = { - url: 'https://emberjs.com', - type: 'POST', - data: stringifiedData - }; - - let options = mungOptionsForFetch(optionsWithStringData); - assert.deepEqual(options.body, stringifiedData); - }); - - test('mungOptionsForFetch does not set a request body when the method is GET or HEAD', function(assert) { - assert.expect(4); - - const baseOptions = { - url: '/', - type: 'GET', - data: { a: 1 } - }; - - let options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - undefined, - 'GET request does not have a request body' - ); - - baseOptions.type = 'HEAD'; - options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - undefined, - 'HEAD request does not have a request body' - ); - - baseOptions.data = {}; - options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - undefined, - 'HEAD request does not have a request body when `data` is an empty object' - ); - - baseOptions.type = 'GET'; - options = mungOptionsForFetch(baseOptions); - assert.equal( - options.body, - undefined, - 'GET request does not have a request body when `data` is an empty object' - ); - }); - - test("mungOptionsForFetch correctly processes an empty 'data' object", function(assert) { - assert.expect(2); - - const getData = { - url: 'https://emberjs.com', - type: 'GET', - data: {} - }; - - const getOptions = mungOptionsForFetch(getData); - assert.equal( - getOptions.url.indexOf('?'), - -1, - 'A question mark is not added if there are no query params to add' - ); - - const postData = { - url: 'https://emberjs.com', - type: 'POST', - data: {} - }; - - const postOptions = mungOptionsForFetch(postData); - assert.equal(postOptions.body, '{}', "'options.body' is an empty object"); - }); - - test("mungOptionsForFetch sets the request body correctly when 'data' is FormData", function(assert) { - assert.expect(1); - - const formData = new FormData() - const postData = { - url: 'https://emberjs.com', - type: 'POST', - data: formData, - }; - - const postOptions = mungOptionsForFetch(postData); - assert.equal(postOptions.body, formData, "'options.body' is the FormData passed in"); - }); - - test("mungOptionsForFetch sets the request body correctly when 'data' has no constructor", function(assert) { - assert.expect(1); - - const data = Object.create(null); - data.request = "body"; - const postData = { - url: 'https://emberjs.com', - type: 'POST', - data: data, - }; - - const postOptions = mungOptionsForFetch(postData); - assert.equal(postOptions.body, JSON.stringify(data), "'options.body' is properly converted to a string"); - }); -});