From e0e2e0c2fb907a282e9a12ab006c9cc27399d88f Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Tue, 18 Aug 2020 14:13:46 -0400 Subject: [PATCH] Added test spec for helpers/util/contenttypes.js --- helpers/utils/__tests__/contenttypes.spec.js | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 helpers/utils/__tests__/contenttypes.spec.js diff --git a/helpers/utils/__tests__/contenttypes.spec.js b/helpers/utils/__tests__/contenttypes.spec.js new file mode 100644 index 000000000..48f9d486e --- /dev/null +++ b/helpers/utils/__tests__/contenttypes.spec.js @@ -0,0 +1,32 @@ +import { isJSONContentType } from "../contenttypes" + +describe("isJSONContentType", () => { + test("returns true for JSON content types", () => { + expect(isJSONContentType("application/json")).toBe(true) + expect(isJSONContentType("application/vnd.api+json")).toBe(true) + expect(isJSONContentType("application/hal+json")).toBe(true) + }) + + test("returns true for JSON types with charset specified", () => { + expect(isJSONContentType("application/json; charset=utf-8")).toBe(true) + expect(isJSONContentType("application/vnd.api+json; charset=utf-8")).toBe(true) + expect(isJSONContentType("application/hal+json; charset=utf-8")).toBe(true) + }) + + test("returns false for non-JSON content types", () => { + expect(isJSONContentType("application/xml")).toBe(false) + expect(isJSONContentType("text/html")).toBe(false) + expect(isJSONContentType("application/x-www-form-urlencoded")).toBe(false) + }) + + test("returns false for non-JSON content types with charset", () => { + expect(isJSONContentType("application/xml; charset=utf-8")).toBe(false) + expect(isJSONContentType("text/html; charset=utf-8")).toBe(false) + expect(isJSONContentType("application/x-www-form-urlencoded; charset=utf-8")).toBe(false) + }) + + test("returns false for null/undefined", () => { + expect(isJSONContentType(null)).toBe(false) + expect(isJSONContentType(undefined)).toBe(false) + }) +})