From bcca69091169cefefe8ddf00b86b79e4c591b025 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 9 Jan 2021 22:00:28 +0100 Subject: [PATCH] mirage/crate: Add derived `max_stable_version` field --- mirage/serializers/crate.js | 2 ++ tests/mirage/crates-test.js | 37 ++++++++++++++++++++++++------------ tests/mirage/summary-test.js | 4 ++++ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/mirage/serializers/crate.js b/mirage/serializers/crate.js index af9da8dcafb..b594754b1de 100644 --- a/mirage/serializers/crate.js +++ b/mirage/serializers/crate.js @@ -1,5 +1,6 @@ import { assert } from '@ember/debug'; +import prerelease from 'semver/functions/prerelease'; import semverSort from 'semver/functions/rsort'; import { compareIsoDates } from '../route-handlers/-utils'; @@ -56,6 +57,7 @@ export default BaseSerializer.extend({ let versionNums = versions.models.map(it => it.num); semverSort(versionNums); hash.max_version = versionNums[0]; + hash.max_stable_version = versionNums.find(it => !prerelease(it)) ?? null; let newestVersions = versions.sort((a, b) => compareIsoDates(b.updated_at, a.updated_at)); hash.newest_version = newestVersions.models[0].num; diff --git a/tests/mirage/crates-test.js b/tests/mirage/crates-test.js index 5b28416c99a..97fcba1aca3 100644 --- a/tests/mirage/crates-test.js +++ b/tests/mirage/crates-test.js @@ -25,7 +25,18 @@ module('Mirage | Crates', function (hooks) { test('returns a paginated crates list', async function (assert) { this.server.create('crate', { name: 'rand' }); - this.server.create('version', { crateId: 'rand', num: '1.0.0' }); + this.server.create('version', { + crateId: 'rand', + created_at: '2020-11-06T12:34:56Z', + num: '1.0.0', + updated_at: '2020-11-06T12:34:56Z', + }); + this.server.create('version', { + crateId: 'rand', + created_at: '2020-12-25T12:34:56Z', + num: '2.0.0-beta.1', + updated_at: '2020-12-25T12:34:56Z', + }); let response = await fetch('/api/v1/crates'); assert.equal(response.status, 200); @@ -50,12 +61,13 @@ module('Mirage | Crates', function (hooks) { version_downloads: '/api/v1/crates/rand/downloads', versions: '/api/v1/crates/rand/versions', }, - max_version: '1.0.0', + max_version: '2.0.0-beta.1', + max_stable_version: '1.0.0', name: 'rand', - newest_version: '1.0.0', + newest_version: '2.0.0-beta.1', repository: null, updated_at: '2017-02-24T12:34:56Z', - versions: ['1'], + versions: ['1', '2'], }, ], meta: { @@ -208,7 +220,7 @@ module('Mirage | Crates', function (hooks) { test('returns a crate object for known crates', async function (assert) { this.server.create('crate', { name: 'rand' }); - this.server.create('version', { crateId: 'rand', num: '1.0.0' }); + this.server.create('version', { crateId: 'rand', num: '1.0.0-beta.1' }); let response = await fetch('/api/v1/crates/rand'); assert.equal(response.status, 200); @@ -233,9 +245,10 @@ module('Mirage | Crates', function (hooks) { version_downloads: '/api/v1/crates/rand/downloads', versions: '/api/v1/crates/rand/versions', }, - max_version: '1.0.0', + max_version: '1.0.0-beta.1', + max_stable_version: null, name: 'rand', - newest_version: '1.0.0', + newest_version: '1.0.0-beta.1', repository: null, updated_at: '2017-02-24T12:34:56Z', versions: ['1'], @@ -247,15 +260,15 @@ module('Mirage | Crates', function (hooks) { crate: 'rand', crate_size: 0, created_at: '2010-06-16T21:30:45Z', - dl_path: '/api/v1/crates/rand/1.0.0/download', + dl_path: '/api/v1/crates/rand/1.0.0-beta.1/download', downloads: 0, license: 'MIT/Apache-2.0', links: { - authors: '/api/v1/crates/rand/1.0.0/authors', - dependencies: '/api/v1/crates/rand/1.0.0/dependencies', - version_downloads: '/api/v1/crates/rand/1.0.0/downloads', + authors: '/api/v1/crates/rand/1.0.0-beta.1/authors', + dependencies: '/api/v1/crates/rand/1.0.0-beta.1/dependencies', + version_downloads: '/api/v1/crates/rand/1.0.0-beta.1/downloads', }, - num: '1.0.0', + num: '1.0.0-beta.1', updated_at: '2017-02-24T12:34:56Z', yanked: false, }, diff --git a/tests/mirage/summary-test.js b/tests/mirage/summary-test.js index 0538afd04f0..08e462ac575 100644 --- a/tests/mirage/summary-test.js +++ b/tests/mirage/summary-test.js @@ -57,6 +57,7 @@ module('Mirage | Summary', function (hooks) { versions: '/api/v1/crates/crate-0/versions', }, max_version: '1.0.0', + max_stable_version: '1.0.0', name: 'crate-0', newest_version: '1.0.0', repository: null, @@ -83,6 +84,7 @@ module('Mirage | Summary', function (hooks) { versions: '/api/v1/crates/crate-4/versions', }, max_version: '1.0.4', + max_stable_version: '1.0.4', name: 'crate-4', newest_version: '1.0.4', repository: null, @@ -109,6 +111,7 @@ module('Mirage | Summary', function (hooks) { versions: '/api/v1/crates/crate-0/versions', }, max_version: '1.0.0', + max_stable_version: '1.0.0', name: 'crate-0', newest_version: '1.0.0', repository: null, @@ -135,6 +138,7 @@ module('Mirage | Summary', function (hooks) { versions: '/api/v1/crates/crate-0/versions', }, max_version: '1.0.0', + max_stable_version: '1.0.0', name: 'crate-0', newest_version: '1.0.0', repository: null,