Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mirage/serializers/crate.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 25 additions & 12 deletions tests/mirage/crates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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'],
Expand All @@ -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,
},
Expand Down
4 changes: 4 additions & 0 deletions tests/mirage/summary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down