mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 13:33:25 +00:00
Add unit tests for body seralization
This commit is contained in:
16
README.md
16
README.md
@@ -10,22 +10,6 @@ features:
|
|||||||
> **This package is still WIP**
|
> **This package is still WIP**
|
||||||
|
|
||||||
Todos:
|
Todos:
|
||||||
- add tests
|
|
||||||
- ProviderControls.runAll()
|
|
||||||
- are events called?
|
|
||||||
- custom source or embed order
|
|
||||||
- are fetchers called?
|
|
||||||
- is proxiedFetcher properly defaulted back to normal fetcher?
|
|
||||||
- ProviderControls.runSourceScraper()
|
|
||||||
- is source scraper called?
|
|
||||||
- does it return as expected?
|
|
||||||
- does it error when invalid type or id?
|
|
||||||
- ProviderControls.runEmbedScraper()
|
|
||||||
- is embed scraper called?
|
|
||||||
- does it return as expected?
|
|
||||||
- does it error when invalid id?
|
|
||||||
- makeStandardFetcher()
|
|
||||||
- does serialisation work as expected? (formdata + json + string)
|
|
||||||
- add all real providers
|
- add all real providers
|
||||||
- make default fetcher maker thing work with both undici and node-fetch
|
- make default fetcher maker thing work with both undici and node-fetch
|
||||||
|
|
||||||
|
39
src/__test__/fetchers/body.test.ts
Normal file
39
src/__test__/fetchers/body.test.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { serializeBody } from "@/fetchers/body";
|
||||||
|
import FormData from "form-data";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
describe("serializeBody()", () => {
|
||||||
|
it('should work with standard text', () => {
|
||||||
|
expect(serializeBody("hello world")).toEqual({
|
||||||
|
headers: {},
|
||||||
|
body: "hello world"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should work with objects', () => {
|
||||||
|
expect(serializeBody({ hello: "world", a: 42 })).toEqual({
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ hello: "world", a: 42 })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should work x-www-form-urlencoded', () => {
|
||||||
|
const obj = new URLSearchParams()
|
||||||
|
obj.set("a", "b");
|
||||||
|
expect(serializeBody(obj)).toEqual({
|
||||||
|
headers: {},
|
||||||
|
body: obj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should work multipart/form-data', () => {
|
||||||
|
const obj = new FormData()
|
||||||
|
obj.append("a", "b");
|
||||||
|
expect(serializeBody(obj)).toEqual({
|
||||||
|
headers: {},
|
||||||
|
body: obj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Reference in New Issue
Block a user