Skip to content

Commit e05ea4f

Browse files
committed
msw: Expose num_versions field on the API
1 parent a93598f commit e05ea4f

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

packages/crates-io-msw/handlers/crates/get.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test('returns a crate object for known crates', async function () {
3838
max_stable_version: null,
3939
name: 'rand',
4040
newest_version: '1.0.0-beta.1',
41+
num_versions: 1,
4142
repository: null,
4243
recent_downloads: 321,
4344
updated_at: '2017-02-24T12:34:56Z',
@@ -101,6 +102,7 @@ test('works for non-canonical names', async function () {
101102
max_stable_version: null,
102103
name: 'foo-bar',
103104
newest_version: '1.0.0-beta.1',
105+
num_versions: 1,
104106
repository: null,
105107
recent_downloads: 321,
106108
updated_at: '2017-02-24T12:34:56Z',

packages/crates-io-msw/handlers/crates/list.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ test('returns a paginated crates list', async function () {
5555
max_stable_version: '1.0.0',
5656
name: 'rand',
5757
newest_version: '2.0.0-beta.1',
58+
num_versions: 2,
5859
repository: null,
5960
recent_downloads: 321,
6061
updated_at: '2017-02-24T12:34:56Z',

packages/crates-io-msw/handlers/summary.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ test('returns the data for the front page', async function () {
5151
max_stable_version: '1.0.0',
5252
name: 'crate-1',
5353
newest_version: '1.0.0',
54+
num_versions: 1,
5455
recent_downloads: 321,
5556
repository: null,
5657
updated_at: '2017-02-24T12:34:56Z',
@@ -81,6 +82,7 @@ test('returns the data for the front page', async function () {
8182
max_stable_version: '1.0.3',
8283
name: 'crate-4',
8384
newest_version: '1.0.3',
85+
num_versions: 1,
8486
repository: null,
8587
recent_downloads: 963,
8688
updated_at: '2017-02-24T12:34:56Z',
@@ -111,6 +113,7 @@ test('returns the data for the front page', async function () {
111113
max_stable_version: '1.0.10',
112114
name: 'crate-11',
113115
newest_version: '1.0.10',
116+
num_versions: 1,
114117
repository: null,
115118
recent_downloads: 3852,
116119
updated_at: '2017-02-24T12:34:56Z',
@@ -141,6 +144,7 @@ test('returns the data for the front page', async function () {
141144
max_stable_version: '1.0.19',
142145
name: 'crate-20',
143146
newest_version: '1.0.19',
147+
num_versions: 1,
144148
repository: null,
145149
recent_downloads: 1605,
146150
updated_at: '2017-02-24T12:34:56Z',

packages/crates-io-msw/serializers/crate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export function serializeCrate(
2727
versionNums.find(it => !versionsByNum[it].yanked) ??
2828
versionNums[0];
2929

30+
serialized.num_versions = versions.length;
31+
3032
serialized.yanked = versionsByNum[serialized.default_version]?.yanked ?? false;
3133

3234
serialized.links = {

0 commit comments

Comments
 (0)