Always test api urls

This commit is contained in:
Sam Carlton 2022-05-21 11:57:59 -05:00
parent ae5f85ffd1
commit bd2fd082f0

View file

@ -4,15 +4,18 @@ import {
generateAPI generateAPI
} from '~/helpers/api/client.js' } from '~/helpers/api/client.js'
import {
isString
} from '~/helpers/check-types.js'
const listingsCases = [ const listingsCases = [
// Spotify // Spotify
[ [
'/app/spotify', '/api/app/spotify.json',
{ {
generateOptions: {}, generateOptions: {},
method: DoesItAPI => DoesItAPI.app.spotify.get(), method: DoesItAPI => DoesItAPI.app.spotify,
expected: { expected: {
name: 'Spotify', name: 'Spotify',
} }
@ -21,37 +24,43 @@ const listingsCases = [
// Electron // Electron
[ [
'/app/electron-framework', '/api/app/electron-framework.json',
{ {
generateOptions: {}, generateOptions: {},
method: DoesItAPI => DoesItAPI.app('electron-framework').get(), method: DoesItAPI => DoesItAPI.app('electron-framework'),
expected: { expected: { name: 'Electron Framework' }
name: 'Electron Framework',
}
} }
], ],
// Express VPN Benchmarks // Express VPN
[ [
'/app/expressvpn/benchmarks/', '/api/app/expressvpn.json',
{ {
generateOptions: {}, generateOptions: {},
method: DoesItAPI => DoesItAPI.app.expressvpn.get(), method: DoesItAPI => DoesItAPI.app.expressvpn,
expected: { expected: { name: 'ExpressVPN' }
name: 'ExpressVPN',
}
} }
], ],
// Solo App URL // Solo App URL
[ [
'/app/solo', '/api/app/solo.json',
{ {
generateOptions: {}, generateOptions: {},
method: DoesItAPI => DoesItAPI.app('solo').url, method: DoesItAPI => DoesItAPI.app('solo'),
expected: result => result.includes( '/app/solo' ) expected: { name: 'SOLO' }
} }
], ],
// Page 2 of App Kinds
[
'/api/kind/app/2.json',
{
generateOptions: {},
method: DoesItAPI => DoesItAPI('kind/app')(2),
expected: result => isString( result.nextPage )
}
]
] ]
@ -64,7 +73,13 @@ test( 'API has valid responses', async t => {
const DoesItAPI = generateAPI( listingCase.generateOptions ) const DoesItAPI = generateAPI( listingCase.generateOptions )
const result = await listingCase.method( DoesItAPI ) const apiMethod = listingCase.method( DoesItAPI )
// Assert that the apiMethod url is correct
t.is( (new URL(apiMethod.url)).pathname, caseEndpoint, `API endpoint '${ caseEndpoint }'` )
// Run get request to fetch our data
const result = await apiMethod.get()
// If expected is a function then call it // If expected is a function then call it
// Otherwise, compare the result to the expected // Otherwise, compare the result to the expected