-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some testing for main data endpoints
- Loading branch information
Showing
4 changed files
with
136 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { SELF } from 'cloudflare:test' | ||
import { describe, expect, it, assert } from 'vitest' | ||
|
||
describe('Books Endpoints', () => { | ||
describe('List', () => { | ||
it('Basic', async () => { | ||
const response = await SELF.fetch('http://example.com/libros') | ||
const json = await response.json() | ||
expect(json).containSubset([ | ||
{ | ||
title: 'Fragmentos a su imán', | ||
}, | ||
]) | ||
}) | ||
it('Should return the amount of books determined in the per_page param', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/libros?per_page=5' | ||
) | ||
const json = await response.json() | ||
expect(json).toHaveLength(5) | ||
}) | ||
it('Should paginate', async () => { | ||
const page1 = await SELF.fetch( | ||
'http://example.com/libros?page=1&per_page=2' | ||
) | ||
const json1 = await page1.json() | ||
const page2 = await SELF.fetch( | ||
'http://example.com/libros?page=2&per_page=2' | ||
) | ||
const json2 = await page2.json() | ||
expect(json1).not.containSubset(json2) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,74 @@ | ||
import { SELF } from 'cloudflare:test' | ||
import { describe, expect, it } from 'vitest' | ||
import { describe, expect, it, assert } from 'vitest' | ||
|
||
describe('Poems Endpoints', () => { | ||
it('list all authors', async () => { | ||
const response = await SELF.fetch('http://example.com/autores') | ||
expect(await response.json()).containSubset([ | ||
{ | ||
name: 'José Lezama Lima', | ||
}, | ||
]) | ||
describe('List', () => { | ||
it('Basic', async () => { | ||
const response = await SELF.fetch('http://example.com/poemas') | ||
const json = await response.json() | ||
expect(json).containSubset([ | ||
{ | ||
title: 'LAS HORAS REGLADAS', | ||
}, | ||
]) | ||
}) | ||
it('Should return the amount of poems determined in the per_page param', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/poemas?per_page=5' | ||
) | ||
const json = await response.json() | ||
expect(json).toHaveLength(5) | ||
}) | ||
it('Should paginate', async () => { | ||
const page1 = await SELF.fetch( | ||
'http://example.com/poemas?page=1&per_page=2' | ||
) | ||
const json1 = await page1.json() | ||
|
||
const page2 = await SELF.fetch( | ||
'http://example.com/poemas?page=2&per_page=2' | ||
) | ||
const json2 = await page2.json() | ||
|
||
expect(json1).not.containSubset(json2) | ||
}) | ||
}) | ||
describe('Fetch', () => { | ||
it('Find the first poem when multiple have the same title', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/poema?title=dador' | ||
) | ||
expect(await response.json()).containSubset({ | ||
title: 'DADOR', | ||
subindex: 1, | ||
}) | ||
}) | ||
it('Find the subindexed poem when multiple have the same title', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/poema?title=dador&subindex=3' | ||
) | ||
expect(await response.json()).containSubset({ | ||
title: 'DADOR', | ||
subindex: 3, | ||
}) | ||
}) | ||
it('Find by id', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/poema?id=rec_cpkejg8v9iqcnjbc1pu0' | ||
) | ||
expect(await response.json()).containSubset({ | ||
title: 'AGUA DEL ESPEJO', | ||
xata_id: 'rec_cpkejg8v9iqcnjbc1pu0', | ||
}) | ||
}) | ||
it('Prioritize id over everything', async () => { | ||
const response = await SELF.fetch( | ||
'http://example.com/poema?id=rec_cpkejg8v9iqcnjbc1pu0&title=DADOR' | ||
) | ||
expect(await response.json()).containSubset({ | ||
title: 'AGUA DEL ESPEJO', | ||
xata_id: 'rec_cpkejg8v9iqcnjbc1pu0', | ||
}) | ||
}) | ||
}) | ||
// it('only list author that match a certain country', () => { | ||
// }) | ||
// it('only list author born after x date', () => { | ||
// }) | ||
// it('only list author born before x date', () => { | ||
// }) | ||
// it('only list author that died after x date', () => { | ||
// }) | ||
// it('only list author that died before x date', () => { | ||
// }) | ||
// it('only list author lived between x-y date', () => { | ||
// }) | ||
}) |