Files
shields/services/wordpress/wordpress-platform.tester.js
Joe Izzard ff3acce7bb [WordPress] API Update (#5579)
* feat: updated to new WordPress API

Updated to the new WordPress API, and separated plugin and theme schemas for future expansion

* test: updated testing for new API

Updated some testing to work with the new API request

* feat: updated schema to require keys

Updated schema to require all the keys in the schema

* fix: remove duplicate requirement

The helper already includes required so we don't need to require it again

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

* fix: remove duplicate requirement

The helper already includes required so we don't need to require it again

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-20 18:31:31 +00:00

135 lines
3.2 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { ServiceTester } = require('../tester')
const { isVPlusDottedVersionAtLeastOne } = require('../test-validators')
const t = (module.exports = new ServiceTester({
id: 'WordpressPlatform',
title: 'WordPress Platform Tests',
pathPrefix: '/wordpress',
}))
t.create('Plugin Required WP Version')
.get('/plugin/wp-version/akismet.json')
.expectBadge({
label: 'wordpress',
message: isVPlusDottedVersionAtLeastOne,
})
t.create('Plugin Tested WP Version')
.get('/plugin/tested/akismet.json')
.expectBadge({
label: 'wordpress',
message: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)? tested$/),
})
const mockedQuerySelector = {
action: 'plugin_information',
request: {
slug: 'akismet',
fields: {
active_installs: '1',
sections: '0',
homepage: '0',
tags: '0',
screenshot_url: '0',
downloaded: 1,
},
},
}
const mockedCoreResponseData = {
offers: [{ version: '4.9.8' }, { version: '4.9.6' }],
}
t.create('Plugin Tested WP Version - current')
.get('/plugin/tested/akismet.json')
.intercept(nock =>
nock('https://api.wordpress.org')
.get('/plugins/info/1.2/')
.query(mockedQuerySelector)
.reply(200, {
version: '1.3',
rating: 80,
num_ratings: 100,
downloaded: 100,
active_installs: 100,
requires: '4.9',
tested: '4.9.8',
})
.get('/core/version-check/1.7/')
.reply(200, mockedCoreResponseData)
)
.expectBadge({
label: 'wordpress',
message: 'v4.9.8 tested',
color: 'brightgreen',
})
t.create('Plugin Tested WP Version - old')
.get('/plugin/tested/akismet.json')
.intercept(nock =>
nock('https://api.wordpress.org')
.get('/plugins/info/1.2/')
.query(mockedQuerySelector)
.reply(200, {
version: '1.2',
rating: 80,
num_ratings: 100,
downloaded: 100,
active_installs: 100,
requires: '4.9',
tested: '4.9.6',
})
.get('/core/version-check/1.7/')
.reply(200, mockedCoreResponseData)
)
.expectBadge({
label: 'wordpress',
message: 'v4.9.6 tested',
color: 'orange',
})
t.create('Plugin Tested WP Version - non-exsistant or unsupported')
.get('/plugin/tested/akismet.json')
.intercept(nock =>
nock('https://api.wordpress.org')
.get('/plugins/info/1.2/')
.query(mockedQuerySelector)
.reply(200, {
version: '1.2',
rating: 80,
num_ratings: 100,
downloaded: 100,
active_installs: 100,
requires: '4.0',
tested: '4.0.0',
})
.get('/core/version-check/1.7/')
.reply(200, mockedCoreResponseData)
)
.expectBadge({
label: 'wordpress',
message: 'v4.0.0 tested',
color: 'yellow',
})
t.create('Plugin Required WP Version | Not Found')
.get('/plugin/wp-version/100.json')
.expectBadge({
label: 'wordpress',
message: 'not found',
})
t.create('Plugin Tested WP Version | Not Found')
.get('/plugin/tested/100.json')
.expectBadge({
label: 'wordpress',
message: 'not found',
})
t.create('Plugin Tested WP Version (Alias)')
.get('/v/100.svg')
.expectRedirect('/wordpress/plugin/tested/100.svg')