Select Git revision
jest.config.ts
tutorial-deprecating-badges.html 9.38 KiB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Tutorial: deprecating-badges</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Tutorial: deprecating-badges</h1>
<section>
<header>
<h2>deprecating-badges</h2>
</header>
<article>
<h1>Deprecating Badges</h1>
<p>When a service that Shields integrates with shuts down, those badges will no longer work and need to be deprecated within Shields.</p>
<p>Deprecating a badge involves two steps:</p>
<ol>
<li>Updating the service code to use the <code>DeprecatedService</code> class</li>
<li>Updating the service tests to reflect the new behavior of the deprecated service</li>
</ol>
<h2>Update Service Implementation</h2>
<p>Locate the source file(s) for the service, which can be found in <code>*.service.js</code> files located within the directory for the service (<code>./services/:service-name/</code>) such as <code>./services/imagelayers/imagelayers.service.js</code>.</p>
<p>Replace the existing service class implementation with the <code>DeprecatedService</code> class from <code>./core/base-service/deprecated-service.js</code> using the respective <code>category</code>, <code>route</code>, and <code>label</code> values for that service. For example:</p>
<pre class="prettyprint source lang-js"><code>'use strict'
const { deprecatedService } = require('..')
module.exports = deprecatedService({
category: 'size',
route: {
base: 'imagelayers',
format: '(?:.+?)',
},
label: 'imagelayers',
dateAdded: new Date('2019-xx-xx'), // Be sure to update this with today's date!
})
</code></pre>
<h2>Update Service Tests</h2>
<p>Locate the test file(s) for the service, which can be found in <code>*.tester.js</code> files located in the service directory (<code>./services/:service-name/</code>), such as <code>./services/imagelayers/imagelayers.tester.js</code>.</p>
<p>With <code>DeprecatedService</code> classes we cannot use <code>createServiceTester()</code> so you will need to create the <code>ServiceTester</code> class directly. For example:</p>
<pre class="prettyprint source lang-js"><code>const { ServiceTester } = require('../tester')
const t = (module.exports = new ServiceTester({
id: 'imagelayers',
title: 'ImageLayers',
}))
</code></pre>
<p>Next you will need to replace/refactor the existing tests to validate the new deprecated badge behavior for this service. Deprecated badges always return a message of <code>no longer available</code> (such as <code>imagelayers | no longer available</code>) so the tests need to be updated to reflect that message value. For example:</p>
<pre class="prettyprint source lang-js"><code>t.create('no longer available (previously image size)')
.get('/image-size/_/ubuntu/latest.json')
.expectBadge({
label: 'imagelayers',
message: 'no longer available',
})
</code></pre>
<p>Make sure to have a live (non-mocked) test for each badge the service provides that validates the each badge returns the <code>no longer available</code> message.</p>
<p>Here is an example of what the final result would look like for a test file:</p>
<pre class="prettyprint source lang-js"><code>'use strict'
const { ServiceTester } = require('../tester')
const t = (module.exports = new ServiceTester({
id: 'imagelayers',
title: 'ImageLayers',
}))
t.create('no longer available (previously image size)')
.get('/image-size/_/ubuntu/latest.json')
.expectBadge({
label: 'imagelayers',
message: 'no longer available',
})
t.create('no longer available (previously number of layers)')
.get('/layers/_/ubuntu/latest.json')
.expectBadge({
label: 'imagelayers',
message: 'no longer available',
})
</code></pre>
<h2>Additional Information</h2>
<p>Some other information that may be useful:</p>
<ul>
<li><a href="../CONTRIBUTING.md">Contributing Docs</a></li>
<li><a href="./TUTORIAL.md">Badge Tutorial</a></li>
<li><a href="./service-tests.md">Service Tests Tutorial</a></li>
<li>Previous Pull Requests that deprecated badges like <a href="https://github.com/badges/shields/pull/2352">#2352</a> and <a href="https://github.com/badges/shields/pull/2410">#2410</a></li>
</ul>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-badge-maker.html">badge-maker</a></li><li><a href="module-core_base-service_base.html">core/base-service/base</a></li><li><a href="module-core_base-service_base-graphql.html">core/base-service/base-graphql</a></li><li><a href="module-core_base-service_base-json.html">core/base-service/base-json</a></li><li><a href="module-core_base-service_base-svg-scraping.html">core/base-service/base-svg-scraping</a></li><li><a href="module-core_base-service_base-xml.html">core/base-service/base-xml</a></li><li><a href="module-core_base-service_base-yaml.html">core/base-service/base-yaml</a></li><li><a href="module-core_base-service_errors.html">core/base-service/errors</a></li><li><a href="module-core_base-service_graphql.html">core/base-service/graphql</a></li><li><a href="module-core_server_server.html">core/server/server</a></li><li><a href="module-core_service-test-runner_create-service-tester.html">core/service-test-runner/create-service-tester</a></li><li><a href="module-core_service-test-runner_icedfrisby-shields.html">core/service-test-runner/icedfrisby-shields</a></li><li><a href="module-core_service-test-runner_infer-pull-request.html">core/service-test-runner/infer-pull-request</a></li><li><a href="module-core_service-test-runner_runner.html">core/service-test-runner/runner</a></li><li><a href="module-core_service-test-runner_service-tester.html">core/service-test-runner/service-tester</a></li><li><a href="module-core_service-test-runner_services-for-title.html">core/service-test-runner/services-for-title</a></li><li><a href="module-core_token-pooling_token-pool.html">core/token-pooling/token-pool</a></li><li><a href="module-services_dynamic_json-path.html">services/dynamic/json-path</a></li><li><a href="module-services_steam_steam-base.html">services/steam/steam-base</a></li></ul><h3>Classes</h3><ul><li><a href="module.exports.html">exports</a></li><li><a href="module-core_base-service_base-graphql-BaseGraphqlService.html">BaseGraphqlService</a></li><li><a href="module-core_base-service_base-json-BaseJsonService.html">BaseJsonService</a></li><li><a href="module-core_base-service_base-svg-scraping-BaseSvgScrapingService.html">BaseSvgScrapingService</a></li><li><a href="module-core_base-service_base-xml-BaseXmlService.html">BaseXmlService</a></li><li><a href="module-core_base-service_base-yaml-BaseYamlService.html">BaseYamlService</a></li><li><a href="module-core_base-service_base-BaseService.html">BaseService</a></li><li><a href="module-core_base-service_errors-Deprecated.html">Deprecated</a></li><li><a href="module-core_base-service_errors-ImproperlyConfigured.html">ImproperlyConfigured</a></li><li><a href="module-core_base-service_errors-Inaccessible.html">Inaccessible</a></li><li><a href="module-core_base-service_errors-InvalidParameter.html">InvalidParameter</a></li><li><a href="module-core_base-service_errors-InvalidResponse.html">InvalidResponse</a></li><li><a href="module-core_base-service_errors-NotFound.html">NotFound</a></li><li><a href="module-core_base-service_errors-ShieldsRuntimeError.html">ShieldsRuntimeError</a></li><li><a href="module-core_server_server-Server.html">Server</a></li><li><a href="module-core_service-test-runner_runner-Runner.html">Runner</a></li><li><a href="module-core_service-test-runner_service-tester-ServiceTester.html">ServiceTester</a></li><li><a href="module-core_token-pooling_token-pool-Token.html">Token</a></li><li><a href="module-core_token-pooling_token-pool-TokenPool.html">TokenPool</a></li><li><a href="module-services_steam_steam-base-BaseSteamAPI.html">BaseSteamAPI</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-TUTORIAL.html">TUTORIAL</a></li><li><a href="tutorial-badge-urls.html">badge-urls</a></li><li><a href="tutorial-code-walkthrough.html">code-walkthrough</a></li><li><a href="tutorial-deprecating-badges.html">deprecating-badges</a></li><li><a href="tutorial-input-validation.html">input-validation</a></li><li><a href="tutorial-json-format.html">json-format</a></li><li><a href="tutorial-logos.html">logos</a></li><li><a href="tutorial-performance-testing.html">performance-testing</a></li><li><a href="tutorial-production-hosting.html">production-hosting</a></li><li><a href="tutorial-rewriting-services.html">rewriting-services</a></li><li><a href="tutorial-self-hosting.html">self-hosting</a></li><li><a href="tutorial-server-secrets.html">server-secrets</a></li><li><a href="tutorial-service-tests.html">service-tests</a></li><li><a href="tutorial-users.html">users</a></li></ul><h3>Global</h3><ul><li><a href="global.html#validateAffiliations">validateAffiliations</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Mon Mar 01 2021 19:22:42 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>