Skip to content

Commit

Permalink
fixed unit tests for routes. #280
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 1, 2020
1 parent 1a1ac3e commit 45e2bde
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 46 deletions.
7 changes: 4 additions & 3 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ Router.map(function() {
this.route('repositories', function() {
this.route('show', { path: '/:repository_id' }, function() {
this.route('settings');
this.route('dois');
this.route('dois', function() {
this.route('new');
this.route('upload');
});
this.route('transfer');
this.route('prefixes', function() {
this.route('show', { path: '/:prefix_id' }, function() {
Expand All @@ -36,8 +39,6 @@ Router.map(function() {
});
});
this.route('dois', function() {
this.route('new');
this.route('upload');
this.route('show', { path: '/:doi_id' }, function() {
this.route('edit');
this.route('modify');
Expand Down
26 changes: 26 additions & 0 deletions app/routes/dois/show/transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
can: service(),

model() {
let self = this;
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'provider,client,resource-type' }).then(function(doi) {
return doi;
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
});
},

afterModel() {
if (this.can.cannot('transfer doi', this.modelFor('dois/show'))) {
this.transitionTo('index');
} else {
this.modelFor('dois/show').set('mode', 'modify');
}
},
});
23 changes: 0 additions & 23 deletions app/routes/dois/upload.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/routes/providers/show/prefixes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Route from '@ember/routing/route';

export default Route.extend({
});
});
4 changes: 4 additions & 0 deletions app/routes/repositories/show/dois.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default Route.extend({
});
4 changes: 4 additions & 0 deletions app/routes/repositories/show/prefixes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default Route.extend({
});
30 changes: 30 additions & 0 deletions app/routes/repositories/show/prefixes/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
can: service(),

model(params) {
let self = this;
return this.store.query('repository-prefix', { 'repository-id': params.repository_id, 'prefix-id': params.prefix_id }).then(function(repositoryPrefixes) {
return repositoryPrefixes.get('firstObject');
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
});
},

afterModel(model) {
if (this.can.cannot('delete prefix', model)) {
this.transitionTo('index');
}
},

actions: {
queryParamsDidChange() {
this.refresh();
},
},
});
12 changes: 1 addition & 11 deletions tests/unit/routes/dois-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ module('Unit | Route | dois', function(hooks) {
assert.ok(route);
});

test('new exists', function(assert) {
let route = this.owner.lookup('route:dois/new');
assert.ok(route);
});

test('upload exists', function(assert) {
let route = this.owner.lookup('route:dois/upload');
assert.ok(route);
});

test('edit exists', function(assert) {
let route = this.owner.lookup('route:dois/show/edit');
assert.ok(route);
Expand All @@ -40,7 +30,7 @@ module('Unit | Route | dois', function(hooks) {
});

test('transfer exists', function(assert) {
let route = this.owner.lookup('route:dois/show/transdfer');
let route = this.owner.lookup('route:dois/show/transfer');
assert.ok(route);
});
});
26 changes: 18 additions & 8 deletions tests/unit/routes/repositories-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,47 @@ module('Unit | Route | repositories', function(hooks) {
});

test('settings exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/settings');
let route = this.owner.lookup('route:repositories/show/settings');
assert.ok(route);
});

test('dois exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/dois');
test('dois/index exists', function(assert) {
let route = this.owner.lookup('route:repositories/show/dois');
assert.ok(route);
});

test('dois/new exists', function(assert) {
let route = this.owner.lookup('route:repositories/show/dois/new');
assert.ok(route);
});

test('dois/upload exists', function(assert) {
let route = this.owner.lookup('route:repositories/show/dois/upload');
assert.ok(route);
});

test('transfer exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/transfer');
let route = this.owner.lookup('route:repositories/show/transfer');
assert.ok(route);
});

test('prefixes exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/prefixes');
let route = this.owner.lookup('route:repositories/show/prefixes');
assert.ok(route);
});

test('prefixes/new exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/prefixes/new');
let route = this.owner.lookup('route:repositories/show/prefixes/new');
assert.ok(route);
});

test('prefixes/show exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/prefixes/show');
let route = this.owner.lookup('route:repositories/show/prefixes/show');
assert.ok(route);
});

test('prefixes/delete exists', function(assert) {
let route = this.owner.lookup('route: repositories/show/prefixes/delete');
let route = this.owner.lookup('route:repositories/show/prefixes/delete');
assert.ok(route);
});
});

0 comments on commit 45e2bde

Please sign in to comment.