|
| 1 | +import { setupTest } from 'ember-qunit'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +import setupMirage from '../helpers/setup-mirage'; |
| 5 | +import fetch from 'fetch'; |
| 6 | + |
| 7 | +module('Mirage | Summary', function(hooks) { |
| 8 | + setupTest(hooks); |
| 9 | + setupMirage(hooks); |
| 10 | + |
| 11 | + module('GET /api/v1/summary', function() { |
| 12 | + test('empty case', async function(assert) { |
| 13 | + let response = await fetch('/api/v1/summary'); |
| 14 | + assert.equal(response.status, 200); |
| 15 | + |
| 16 | + let responsePayload = await response.json(); |
| 17 | + assert.matchJson(responsePayload, { |
| 18 | + just_updated: [], |
| 19 | + most_downloaded: [], |
| 20 | + most_recently_downloaded: [], |
| 21 | + new_crates: [], |
| 22 | + num_crates: 0, |
| 23 | + num_downloads: 0, |
| 24 | + popular_categories: [], |
| 25 | + popular_keywords: [], |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + test('returns the data for the front page', async function(assert) { |
| 30 | + this.server.createList('category', 15); |
| 31 | + this.server.createList('keyword', 25); |
| 32 | + this.server.createList('crate', 20); |
| 33 | + |
| 34 | + let response = await fetch('/api/v1/summary'); |
| 35 | + assert.equal(response.status, 200); |
| 36 | + |
| 37 | + let responsePayload = await response.json(); |
| 38 | + |
| 39 | + assert.equal(responsePayload.just_updated.length, 10); |
| 40 | + assert.matchJson(responsePayload.just_updated[0], { |
| 41 | + id: 'crate-8', |
| 42 | + badges: [], |
| 43 | + categories: [], |
| 44 | + created_at: '2017-02-12T22:12:49.418Z', |
| 45 | + description: 'Harum sit numquam eos voluptatem quidem et.', |
| 46 | + documentation: 'https://parker.info', |
| 47 | + downloads: 1379, |
| 48 | + homepage: 'https://alena.com', |
| 49 | + keywords: [], |
| 50 | + links: { |
| 51 | + owner_team: '/api/v1/crates/crate-8/owner_team', |
| 52 | + owner_user: '/api/v1/crates/crate-8/owner_user', |
| 53 | + reverse_dependencies: '/api/v1/crates/crate-8/reverse_dependencies', |
| 54 | + version_downloads: '/api/v1/crates/crate-8/downloads', |
| 55 | + versions: '/api/v1/crates/crate-8/versions', |
| 56 | + }, |
| 57 | + max_version: '6.6.5', |
| 58 | + name: 'crate-8', |
| 59 | + newest_version: '6.2.7', |
| 60 | + repository: 'http://idell.org', |
| 61 | + updated_at: '2017-11-18T02:53:33.362Z', |
| 62 | + versions: null, |
| 63 | + }); |
| 64 | + |
| 65 | + assert.equal(responsePayload.most_downloaded.length, 10); |
| 66 | + assert.matchJson(responsePayload.most_downloaded[0], { |
| 67 | + id: 'crate-10', |
| 68 | + badges: [], |
| 69 | + categories: [], |
| 70 | + created_at: '2017-09-02T17:58:59.344Z', |
| 71 | + description: 'Vero et numquam soluta laboriosam quia eaque quod ut optio.', |
| 72 | + documentation: 'https://retta.org', |
| 73 | + downloads: 9122, |
| 74 | + homepage: 'http://curt.org', |
| 75 | + keywords: [], |
| 76 | + links: { |
| 77 | + owner_team: '/api/v1/crates/crate-10/owner_team', |
| 78 | + owner_user: '/api/v1/crates/crate-10/owner_user', |
| 79 | + reverse_dependencies: '/api/v1/crates/crate-10/reverse_dependencies', |
| 80 | + version_downloads: '/api/v1/crates/crate-10/downloads', |
| 81 | + versions: '/api/v1/crates/crate-10/versions', |
| 82 | + }, |
| 83 | + max_version: '1.4.7', |
| 84 | + name: 'crate-10', |
| 85 | + newest_version: '5.5.5', |
| 86 | + repository: 'http://melba.biz', |
| 87 | + updated_at: '2017-11-05T02:24:22.509Z', |
| 88 | + versions: null, |
| 89 | + }); |
| 90 | + |
| 91 | + assert.equal(responsePayload.most_recently_downloaded.length, 10); |
| 92 | + assert.matchJson(responsePayload.most_recently_downloaded[0], { |
| 93 | + id: 'crate-0', |
| 94 | + badges: [], |
| 95 | + categories: [], |
| 96 | + created_at: '2017-01-02T07:07:20.191Z', |
| 97 | + description: 'Voluptate deleniti modi voluptatem fugiat autem omnis.', |
| 98 | + documentation: 'https://taylor.com', |
| 99 | + downloads: 6816, |
| 100 | + homepage: 'http://rubye.org', |
| 101 | + keywords: [], |
| 102 | + links: { |
| 103 | + owner_team: '/api/v1/crates/crate-0/owner_team', |
| 104 | + owner_user: '/api/v1/crates/crate-0/owner_user', |
| 105 | + reverse_dependencies: '/api/v1/crates/crate-0/reverse_dependencies', |
| 106 | + version_downloads: '/api/v1/crates/crate-0/downloads', |
| 107 | + versions: '/api/v1/crates/crate-0/versions', |
| 108 | + }, |
| 109 | + max_version: '2.0.4', |
| 110 | + name: 'crate-0', |
| 111 | + newest_version: '6.9.2', |
| 112 | + repository: 'http://cassandre.org', |
| 113 | + updated_at: '2017-10-14T18:55:43.747Z', |
| 114 | + versions: null, |
| 115 | + }); |
| 116 | + |
| 117 | + assert.equal(responsePayload.new_crates.length, 10); |
| 118 | + assert.matchJson(responsePayload.new_crates[0], { |
| 119 | + id: 'crate-13', |
| 120 | + badges: [], |
| 121 | + categories: [], |
| 122 | + created_at: '2017-11-03T08:55:49.568Z', |
| 123 | + description: 'Suscipit omnis vitae nobis et recusandae error.', |
| 124 | + documentation: 'http://blake.org', |
| 125 | + downloads: 4019, |
| 126 | + homepage: 'http://retta.biz', |
| 127 | + keywords: [], |
| 128 | + links: { |
| 129 | + owner_team: '/api/v1/crates/crate-13/owner_team', |
| 130 | + owner_user: '/api/v1/crates/crate-13/owner_user', |
| 131 | + reverse_dependencies: '/api/v1/crates/crate-13/reverse_dependencies', |
| 132 | + version_downloads: '/api/v1/crates/crate-13/downloads', |
| 133 | + versions: '/api/v1/crates/crate-13/versions', |
| 134 | + }, |
| 135 | + max_version: '0.9.6', |
| 136 | + name: 'crate-13', |
| 137 | + newest_version: '7.3.3', |
| 138 | + repository: 'http://shirley.net', |
| 139 | + updated_at: '2017-11-06T13:45:18.068Z', |
| 140 | + versions: null, |
| 141 | + }); |
| 142 | + |
| 143 | + assert.equal(responsePayload.num_crates, 20); |
| 144 | + assert.equal(responsePayload.num_downloads, 86789); |
| 145 | + |
| 146 | + assert.equal(responsePayload.popular_categories.length, 10); |
| 147 | + assert.matchJson(responsePayload.popular_categories[0], { |
| 148 | + id: 'category-13', |
| 149 | + category: 'Category 13', |
| 150 | + crate_ids: [], |
| 151 | + crates_cnt: 4708, |
| 152 | + created_at: '2017-06-09T00:19:17.301Z', |
| 153 | + description: 'Voluptas voluptatem culpa aspernatur vel atque.', |
| 154 | + slug: 'category-13', |
| 155 | + }); |
| 156 | + |
| 157 | + assert.equal(responsePayload.popular_keywords.length, 10); |
| 158 | + assert.matchJson(responsePayload.popular_keywords[0], { |
| 159 | + id: '1', |
| 160 | + crate_ids: [], |
| 161 | + }); |
| 162 | + }); |
| 163 | + }); |
| 164 | +}); |
0 commit comments