Add tests for api client

This commit is contained in:
Sam Carlton 2022-05-21 11:25:18 -05:00
parent 7ebee653c6
commit ef065423cc
2 changed files with 82 additions and 2 deletions

View file

@ -20,9 +20,10 @@
}, },
"scripts": { "scripts": {
"test-prebuild": "ava ./test/prebuild/**/*.js --verbose", "test-prebuild": "ava ./test/prebuild/**/*.js --verbose",
"test-prebuild-functions": "npm run test-prebuild && npm run test-listings", "test-api-client": "ava ./test/api/client.js --verbose",
"test-postbuild-api": "npm run test-listings",
"test-listings": "ava ./test/listings/**/*.js --verbose", "test-listings": "ava ./test/listings/**/*.js --verbose",
"test-prebuild-functions": "run-s test-prebuild test-api-client test-listings",
"test-postbuild-api": "run-s test-listings",
"test": "ava --timeout=1m --verbose", "test": "ava --timeout=1m --verbose",
"dev": "nuxt", "dev": "nuxt",
"build": "nuxt build", "build": "nuxt build",

79
test/api/client.js Normal file
View file

@ -0,0 +1,79 @@
import test from 'ava'
import {
generateAPI
} from '~/helpers/api/client.js'
const listingsCases = [
// Spotify
[
'/app/spotify',
{
generateOptions: {},
method: DoesItAPI => DoesItAPI.app.spotify.get(),
expected: {
name: 'Spotify',
}
}
],
// Electron
[
'/app/electron-framework',
{
generateOptions: {},
method: DoesItAPI => DoesItAPI.app('electron-framework').get(),
expected: {
name: 'Electron Framework',
}
}
],
// Express VPN Benchmarks
[
'/app/expressvpn/benchmarks/',
{
generateOptions: {},
method: DoesItAPI => DoesItAPI.app.expressvpn.get(),
expected: {
name: 'ExpressVPN',
}
}
],
// Solo App URL
[
'/app/solo',
{
generateOptions: {},
method: DoesItAPI => DoesItAPI.app('solo').url,
expected: result => result.includes( '/app/solo' )
}
],
]
test( 'API has valid responses', async t => {
// const { listingsDetails } = t.context
for ( const [ caseEndpoint, listingCase ] of listingsCases ) {
// const apiPath = listingsDetails[ caseEndpoint ].apiEndpointPath
const DoesItAPI = generateAPI( listingCase.generateOptions )
const result = await listingCase.method( DoesItAPI )
// If expected is a function then call it
// Otherwise, compare the result to the expected
if ( typeof listingCase.expected === 'function' ) {
t.assert( listingCase.expected( result ), `API case method check for '${ caseEndpoint }'` )
continue
}
t.like( result, listingCase.expected, `${ caseEndpoint } has a valid api endpoint` )
}
})