Skip to content

Add tests for the mirage mock server implemenation #2120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
883516e
Add tests for `GET /api/v1/categories/:id` mirage request handler
Turbo87 Jan 14, 2020
0b458ec
Add tests for `GET /api/v1/categories` mirage request handler
Turbo87 Jan 14, 2020
8c97bb5
Add tests for `GET /api/v1/category_slugs` mirage request handler
Turbo87 Jan 14, 2020
768139a
Add tests for `GET /api/v1/keywords` mirage request handler
Turbo87 Jan 14, 2020
b9128f3
Add tests for `GET /api/v1/keywords/:id` mirage request handler
Turbo87 Jan 14, 2020
977042f
Add tests for `GET /api/v1/teams/:id` mirage request handler
Turbo87 Jan 14, 2020
8c55aca
Add tests for `GET /api/v1/users/:id` mirage request handler
Turbo87 Jan 14, 2020
0f216cb
Add tests for `GET /api/v1/crates` mirage request handler
Turbo87 Jan 14, 2020
21b71b9
Add tests for `GET /api/v1/crates/:id` mirage request handler
Turbo87 Jan 14, 2020
ce7e238
Add tests for `GET /api/v1/crates/:id/versions` mirage request handler
Turbo87 Jan 15, 2020
e53425e
Add tests for `GET /api/v1/crates/:id/:version/authors` mirage reques…
Turbo87 Jan 15, 2020
b1ea91a
Add tests for `GET /api/v1/crates/:id/:version/dependencies` mirage r…
Turbo87 Jan 15, 2020
cba2f81
Add tests for `GET /api/v1/crates/:id/:version/downloads` mirage requ…
Turbo87 Jan 15, 2020
2f79d35
Add tests for `GET /api/v1/crates/:id/owner_user` mirage request handler
Turbo87 Jan 15, 2020
e4ed29b
Add tests for `GET /api/v1/crates/:id/owner_team` mirage request handler
Turbo87 Jan 15, 2020
4f2a797
Add tests for `GET /api/v1/crates/:id/reverse_dependencies` mirage re…
Turbo87 Jan 15, 2020
0f11af4
Add tests for `GET /api/v1/crates/:id/downloads` mirage request handler
Turbo87 Jan 15, 2020
32a5201
Add tests for `GET /api/v1/summary` mirage request handler
Turbo87 Jan 13, 2020
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
183 changes: 183 additions & 0 deletions tests/mirage/categories-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

import setupMirage from '../helpers/setup-mirage';
import fetch from 'fetch';

module('Mirage | Categories', function(hooks) {
setupTest(hooks);
setupMirage(hooks);

module('GET /api/v1/categories', function() {
test('empty case', async function(assert) {
let response = await fetch('/api/v1/categories');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, {
categories: [],
meta: {
total: 0,
},
});
});

test('returns a paginated categories list', async function(assert) {
this.server.create('category', {
category: 'no-std',
description: 'Crates that are able to function without the Rust standard library.',
});
this.server.createList('category', 2);

let response = await fetch('/api/v1/categories');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, {
categories: [
{
id: 'category-1',
category: 'Category 1',
crates_cnt: 0,
created_at: '2010-06-16T21:30:45Z',
description: 'This is the description for the category called "Category 1"',
slug: 'category-1',
},
{
id: 'category-2',
category: 'Category 2',
crates_cnt: 0,
created_at: '2010-06-16T21:30:45Z',
description: 'This is the description for the category called "Category 2"',
slug: 'category-2',
},
{
id: 'no-std',
category: 'no-std',
crates_cnt: 0,
created_at: '2010-06-16T21:30:45Z',
description: 'Crates that are able to function without the Rust standard library.',
slug: 'no-std',
},
],
meta: {
total: 3,
},
});
});

test('never returns more than 10 results', async function(assert) {
this.server.createList('category', 25);

let response = await fetch('/api/v1/categories');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.equal(responsePayload.categories.length, 10);
assert.equal(responsePayload.meta.total, 25);
});

test('supports `page` and `per_page` parameters', async function(assert) {
this.server.createList('category', 25, {
category: i => `cat-${String(i + 1).padStart(2, '0')}`,
});

let response = await fetch('/api/v1/categories?page=2&per_page=5');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.equal(responsePayload.categories.length, 5);
assert.deepEqual(
responsePayload.categories.map(it => it.id),
['cat-06', 'cat-07', 'cat-08', 'cat-09', 'cat-10'],
);
assert.equal(responsePayload.meta.total, 25);
});
});

module('GET /api/v1/categories/:id', function() {
test('returns 404 for unknown categories', async function(assert) {
let response = await fetch('/api/v1/categories/foo');
assert.equal(response.status, 404);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, { errors: [{ detail: 'Not Found' }] });
});

test('returns a category object for known categories', async function(assert) {
this.server.create('category', {
category: 'no-std',
description: 'Crates that are able to function without the Rust standard library.',
});

let response = await fetch('/api/v1/categories/no-std');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, {
category: {
id: 'no-std',
category: 'no-std',
crates_cnt: 0,
created_at: '2010-06-16T21:30:45Z',
description: 'Crates that are able to function without the Rust standard library.',
slug: 'no-std',
},
});
});
});

module('GET /api/v1/category_slugs', function() {
test('empty case', async function(assert) {
let response = await fetch('/api/v1/category_slugs');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, {
category_slugs: [],
});
});

test('returns a category slugs list', async function(assert) {
this.server.create('category', {
category: 'no-std',
description: 'Crates that are able to function without the Rust standard library.',
});
this.server.createList('category', 2);

let response = await fetch('/api/v1/category_slugs');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.deepEqual(responsePayload, {
category_slugs: [
{
description: 'This is the description for the category called "Category 1"',
id: 'category-1',
slug: 'category-1',
},
{
description: 'This is the description for the category called "Category 2"',
id: 'category-2',
slug: 'category-2',
},
{
description: 'Crates that are able to function without the Rust standard library.',
id: 'no-std',
slug: 'no-std',
},
],
});
});

test('has no pagination', async function(assert) {
this.server.createList('category', 25);

let response = await fetch('/api/v1/category_slugs');
assert.equal(response.status, 200);

let responsePayload = await response.json();
assert.equal(responsePayload.category_slugs.length, 25);
});
});
});
Loading