mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add tests for api client
This commit is contained in:
parent
7ebee653c6
commit
ef065423cc
2 changed files with 82 additions and 2 deletions
|
|
@ -20,9 +20,10 @@
|
|||
},
|
||||
"scripts": {
|
||||
"test-prebuild": "ava ./test/prebuild/**/*.js --verbose",
|
||||
"test-prebuild-functions": "npm run test-prebuild && npm run test-listings",
|
||||
"test-postbuild-api": "npm run test-listings",
|
||||
"test-api-client": "ava ./test/api/client.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",
|
||||
"dev": "nuxt",
|
||||
"build": "nuxt build",
|
||||
|
|
|
|||
79
test/api/client.js
Normal file
79
test/api/client.js
Normal 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` )
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue