Skip to content

Commit d7800dd

Browse files
committed
Auto merge of #3169 - Turbo87:top-versions-mirage, r=pichfl
mirage/crate: Add derived `max_stable_version` field This PR implements #3163 for our fake testing API on the frontend to eventually address #654 r? `@pichfl`
2 parents 75f5ac8 + bcca690 commit d7800dd

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

mirage/serializers/crate.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assert } from '@ember/debug';
22

3+
import prerelease from 'semver/functions/prerelease';
34
import semverSort from 'semver/functions/rsort';
45

56
import { compareIsoDates } from '../route-handlers/-utils';
@@ -56,6 +57,7 @@ export default BaseSerializer.extend({
5657
let versionNums = versions.models.map(it => it.num);
5758
semverSort(versionNums);
5859
hash.max_version = versionNums[0];
60+
hash.max_stable_version = versionNums.find(it => !prerelease(it)) ?? null;
5961

6062
let newestVersions = versions.sort((a, b) => compareIsoDates(b.updated_at, a.updated_at));
6163
hash.newest_version = newestVersions.models[0].num;

tests/mirage/crates-test.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ module('Mirage | Crates', function (hooks) {
2525

2626
test('returns a paginated crates list', async function (assert) {
2727
this.server.create('crate', { name: 'rand' });
28-
this.server.create('version', { crateId: 'rand', num: '1.0.0' });
28+
this.server.create('version', {
29+
crateId: 'rand',
30+
created_at: '2020-11-06T12:34:56Z',
31+
num: '1.0.0',
32+
updated_at: '2020-11-06T12:34:56Z',
33+
});
34+
this.server.create('version', {
35+
crateId: 'rand',
36+
created_at: '2020-12-25T12:34:56Z',
37+
num: '2.0.0-beta.1',
38+
updated_at: '2020-12-25T12:34:56Z',
39+
});
2940

3041
let response = await fetch('/api/v1/crates');
3142
assert.equal(response.status, 200);
@@ -50,12 +61,13 @@ module('Mirage | Crates', function (hooks) {
5061
version_downloads: '/api/v1/crates/rand/downloads',
5162
versions: '/api/v1/crates/rand/versions',
5263
},
53-
max_version: '1.0.0',
64+
max_version: '2.0.0-beta.1',
65+
max_stable_version: '1.0.0',
5466
name: 'rand',
55-
newest_version: '1.0.0',
67+
newest_version: '2.0.0-beta.1',
5668
repository: null,
5769
updated_at: '2017-02-24T12:34:56Z',
58-
versions: ['1'],
70+
versions: ['1', '2'],
5971
},
6072
],
6173
meta: {
@@ -208,7 +220,7 @@ module('Mirage | Crates', function (hooks) {
208220

209221
test('returns a crate object for known crates', async function (assert) {
210222
this.server.create('crate', { name: 'rand' });
211-
this.server.create('version', { crateId: 'rand', num: '1.0.0' });
223+
this.server.create('version', { crateId: 'rand', num: '1.0.0-beta.1' });
212224

213225
let response = await fetch('/api/v1/crates/rand');
214226
assert.equal(response.status, 200);
@@ -233,9 +245,10 @@ module('Mirage | Crates', function (hooks) {
233245
version_downloads: '/api/v1/crates/rand/downloads',
234246
versions: '/api/v1/crates/rand/versions',
235247
},
236-
max_version: '1.0.0',
248+
max_version: '1.0.0-beta.1',
249+
max_stable_version: null,
237250
name: 'rand',
238-
newest_version: '1.0.0',
251+
newest_version: '1.0.0-beta.1',
239252
repository: null,
240253
updated_at: '2017-02-24T12:34:56Z',
241254
versions: ['1'],
@@ -247,15 +260,15 @@ module('Mirage | Crates', function (hooks) {
247260
crate: 'rand',
248261
crate_size: 0,
249262
created_at: '2010-06-16T21:30:45Z',
250-
dl_path: '/api/v1/crates/rand/1.0.0/download',
263+
dl_path: '/api/v1/crates/rand/1.0.0-beta.1/download',
251264
downloads: 0,
252265
license: 'MIT/Apache-2.0',
253266
links: {
254-
authors: '/api/v1/crates/rand/1.0.0/authors',
255-
dependencies: '/api/v1/crates/rand/1.0.0/dependencies',
256-
version_downloads: '/api/v1/crates/rand/1.0.0/downloads',
267+
authors: '/api/v1/crates/rand/1.0.0-beta.1/authors',
268+
dependencies: '/api/v1/crates/rand/1.0.0-beta.1/dependencies',
269+
version_downloads: '/api/v1/crates/rand/1.0.0-beta.1/downloads',
257270
},
258-
num: '1.0.0',
271+
num: '1.0.0-beta.1',
259272
updated_at: '2017-02-24T12:34:56Z',
260273
yanked: false,
261274
},

tests/mirage/summary-test.js

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module('Mirage | Summary', function (hooks) {
5757
versions: '/api/v1/crates/crate-0/versions',
5858
},
5959
max_version: '1.0.0',
60+
max_stable_version: '1.0.0',
6061
name: 'crate-0',
6162
newest_version: '1.0.0',
6263
repository: null,
@@ -83,6 +84,7 @@ module('Mirage | Summary', function (hooks) {
8384
versions: '/api/v1/crates/crate-4/versions',
8485
},
8586
max_version: '1.0.4',
87+
max_stable_version: '1.0.4',
8688
name: 'crate-4',
8789
newest_version: '1.0.4',
8890
repository: null,
@@ -109,6 +111,7 @@ module('Mirage | Summary', function (hooks) {
109111
versions: '/api/v1/crates/crate-0/versions',
110112
},
111113
max_version: '1.0.0',
114+
max_stable_version: '1.0.0',
112115
name: 'crate-0',
113116
newest_version: '1.0.0',
114117
repository: null,
@@ -135,6 +138,7 @@ module('Mirage | Summary', function (hooks) {
135138
versions: '/api/v1/crates/crate-0/versions',
136139
},
137140
max_version: '1.0.0',
141+
max_stable_version: '1.0.0',
138142
name: 'crate-0',
139143
newest_version: '1.0.0',
140144
repository: null,

0 commit comments

Comments
 (0)