Skip to content

Commit

Permalink
Merge pull request #365 from datacite/add_tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
Martin Fenner authored Mar 16, 2020
2 parents a020a12 + 7359795 commit 9bb32fd
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export default DS.Model.extend({

meta: DS.attr(),

created: DS.attr('date'),
createdAt: DS.attr('date'),
});
2 changes: 1 addition & 1 deletion app/models/provider-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default DS.Model.extend(Validations, {
async: false,
}),

created: DS.attr('date'),
createdAt: DS.attr('date'),
});
2 changes: 1 addition & 1 deletion app/models/repository-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default DS.Model.extend({
async: true,
}),

created: DS.attr('date'),
createdAt: DS.attr('date'),
});
3 changes: 2 additions & 1 deletion app/routes/providers/show/prefixes/delete.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';

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

model(params) {
let self = this;
return this.store.query('provider-prefix', { 'provider-id': params['provider-id'], 'prefix-id': params['prefix-id'] }).then(function(providerPrefixes) {
return providerPrefixes.get('firstObject');
return A(providerPrefixes).get('firstObject');
}).catch(function(reason) {
console.debug(reason);

Expand Down
3 changes: 2 additions & 1 deletion app/routes/repositories/show/prefixes/delete.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';

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');
return A(repositoryPrefixes).get('firstObject');
}).catch(function(reason) {
console.debug(reason);

Expand Down
2 changes: 1 addition & 1 deletion app/routes/repositories/show/prefixes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default Route.extend({
number: params.page,
size: params.size,
},
'client-id': this.modelFor('repositories/show').get('id'),
'repository-id': this.modelFor('repositories/show').get('id'),
});

return hash({
Expand Down
3 changes: 2 additions & 1 deletion app/routes/repositories/show/prefixes/show.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';

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');
return A(repositoryPrefixes).get('firstObject');
}).catch(function(reason) {
console.debug(reason);

Expand Down
6 changes: 3 additions & 3 deletions app/templates/prefixes/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{#if model.meta.providers}}
<div class="panel facets">
<div class="panel-body">
<h4>Providers <span class="small">{{fa-icon "question-circle-o"}}<BsTooltip @placement="top">Filter prefixes by DOI Registration Provider they work with.</BsTooltip></span></h4>
<h4>Member</h4>
<ul>
{{#each model.meta.providers as |provider|}}
<li>
Expand Down Expand Up @@ -98,7 +98,7 @@
<div class="panel-body">
<h3 class="member">{{prefix.id}}</h3>

<h5>{{pluralize prefix.providers.length "Provider" without-count=true}}</h5>
<h5>{{pluralize prefix.providers.length "Member" without-count=true}}</h5>
{{#if prefix.providers}}
{{#each prefix.providers as |provider|}}
<LinkTo @route="providers.show.prefixes.show" @models={{array provider.id prefix.id}}>{{provider.name}}</LinkTo><br/>
Expand All @@ -121,7 +121,7 @@
{{/if}}

<h5>Created</h5>
{{format-time prefix.created year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
{{format-time prefix.createdAt year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
</div>
</div>
{{/each}}
Expand Down
4 changes: 2 additions & 2 deletions app/templates/providers/show/prefixes/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{{#if (eq link "prefixes")}}
<div class="panel facets">
<div class="panel-body">
<h4>Providers <span class="small">{{fa-icon "question-circle-o"}}<BsTooltip @placement="top">Filter prefixes by DOI Registration Provider they work with.</BsTooltip></span></h4>
<h4>Members</h4>
<ul>
{{#each model.prefixes.meta.providers as |provider|}}
<li>
Expand Down Expand Up @@ -109,7 +109,7 @@
{{/if}}

<h5>Added</h5>
{{format-time providerPrefix.created year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
{{format-time providerPrefix.createdAt year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
</div>
</div>
{{/each}}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/repositories/show/prefixes/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{{/if}}

<h5>Added</h5>
{{format-time repositoryPrefix.created year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
{{format-time repositoryPrefix.createdAt year='numeric' month='long' day='numeric' hour='numeric' minute='numeric' second='numeric' timeZone='UTC' timeZoneName='short' hour12=false}}
</div>
</div>
{{/each}}
Expand Down
26 changes: 26 additions & 0 deletions tests/factories/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('provider', {
default: {
memberType: 'direct_member',
technicalContact: { },
secondaryTechnicalContact: { },
billingContact: {
email: '[email protected]',
givenName: 'Adrian',
familyName: 'Burton',
},
secondaryBillingContact: {
email: '[email protected]',
givenName: 'David',
familyName: 'Vitkin',
},
serviceContact: {
email: '[email protected]',
givenName: 'ARDC Services',
},
secondaryServiceContact: { },
votingContact: { },
},

});
39 changes: 39 additions & 0 deletions tests/factories/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,51 @@ import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('provider', {
default: {
name: 'Australian Research Data Commons',
displayName: 'Australian Research Data Commons',
symbol: 'ANDS',
website: 'https://ardc.edu.au/',
systemEmail: '[email protected]',
groupEmail: null,
description: '',
region: 'APAC',
country: 'AU',
logoUrl: 'https://assets.datacite.org/images/members/ands.png?1583249855',
memberType: 'direct_member',
organizationType: 'nationalInstitution',
focusArea: 'general',
nonProfitStatus: 'non-profit',
isActive: true,
hasPassword: true,
joined: '2010-02-05',
rorId: 'https://ror.org/038sjwq14',
},

ands: {
id: 'ands',
name: 'Australian National Data Service',
systemEmail: '[email protected]',
},

// organisation: {
// memberType: 'direct_member',
// technicalContact: { },
// secondaryTechnicalContact: { },
// billingContact: {
// email: '[email protected]',
// givenName: 'Adrian',
// familyName: 'Burton',
// },
// secondaryBillingContact: {
// email: '[email protected]',
// givenName: 'David',
// familyName: 'Vitkin',
// },
// serviceContact: {
// email: '[email protected]',
// givenName: 'ARDC Services',
// },
// secondaryServiceContact: { },
// votingContact: { },
// },
});
2 changes: 1 addition & 1 deletion tests/integration/helpers/provider-form-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ module('Integration | Helper | provider-form-errors', function(hooks) {

await render(hbs`{{provider-form-errors model}}`);

assert.dom(this.element).hasText('member ID, confirm member ID, provider name, provider display name, system email');
assert.dom(this.element).hasText('confirm member ID');
});
});
17 changes: 17 additions & 0 deletions tests/unit/controllers/dois-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
// import { setupFactoryGuy, make } from 'ember-data-factory-guy';

module('Unit | Controller | dois', function(hooks) {
setupTest(hooks);
// setupFactoryGuy(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:dois');
assert.ok(controller);
});

// promise error needs to be fixed
/*
test('should edit doi', function(assert) {
let controller = this.owner.lookup('controller:dois.show.edit');
let doi = make('doi');
let store = this.owner.lookup('service:store');
let originalSource = store.peekRecord('doi', 1).get('source');
assert.equal(originalSource,'fabrica');
controller.send('submit', doi);
let targetSource = store.peekRecord('doi', 1).get('source');
assert.equal(targetSource,'fabricaForm');
});
*/

});
100 changes: 100 additions & 0 deletions tests/unit/controllers/providers-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,112 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupFactoryGuy, make } from 'ember-data-factory-guy';

module('Unit | Controller | providers', function(hooks) {
setupTest(hooks);
setupFactoryGuy(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:providers');
assert.ok(controller);
});

test('should list countries', function(assert) {
let controller = this.owner.lookup('controller:providers.show.organizations.new');
let model = {
'provider': make('provider'),
'organization': make('provider', { memberType: 'consortium_organization' }),
};
controller.set('model', model);
controller.send('selectCountry', 'Australia');
assert.equal(controller.model.organization.get('country'), 'Australia');
controller.send('searchCountry', 'Australia');
assert.equal(controller.get('countries').length,1);
});

test('should list organisation type list', function(assert) {
let controller = this.owner.lookup('controller:providers.show.organizations.new');

let model = {
'provider': make('provider'),
'organization': make('provider', { memberType: 'consortium_organization' }),
};
controller.set('model', model);
controller.send('selectOrganizationType', 'nationalInstitution');
assert.equal(controller.model.organization.get('organizationType'), 'nationalInstitution');
controller.send('searchOrganizationType', 'National');
assert.equal(controller.get('organizationTypes').length,1);
});

test('should list member type list', function(assert) {
let controller = this.owner.lookup('controller:providers.show.organizations.new');
let model = {
'provider': make('provider'),
'organization': make('provider', { memberType: 'consortium_organization' }),
};
controller.set('model', model);
controller.send('selectMemberType', 'direct_member');
assert.equal(controller.model.organization.get('memberType'), 'direct_member');
controller.send('searchMemberType', 'direct_member');
assert.equal(controller.get('memberTypes').length,1);
});

test('should list focus area list', function(assert) {
let controller = this.owner.lookup('controller:providers.show.organizations.new');
let model = {
'provider': make('provider'),
'organization': make('provider', { memberType: 'consortium_organization' }),
};
controller.set('model', model);
controller.send('selectFocusArea', 'general');
assert.equal(controller.model.organization.get('focusArea'), 'general');
controller.send('searchFocusArea', 'general');
assert.equal(controller.get('focusAreas').length,1);
});

test('should list non profit status list', function(assert) {
let controller = this.owner.lookup('controller:providers.show.organizations.new');
let model = {
'provider': make('provider'),
'organization': make('provider', { memberType: 'consortium_organization' }),
};
controller.set('model', model);
controller.send('selectFocusArea', 'general');
assert.equal(controller.model.organization.get('focusArea'), 'general');
controller.send('searchFocusArea', 'general');
assert.equal(controller.get('focusAreas').length,1);
});

// I don't know how to test for consortium either
// test('should list consortium', function(assert) {
// let controller = this.owner.lookup('controller:providers.show.organizations.new');
// let model = {
// 'provider': make('provider'),
// 'organization': make('provider', { memberType: 'consortium_organization' }),
// };
// controller.set('model', model);
// controller.send('searchConsortium', '');
// assert.equal(controller.model.organization.get('consortia'), '');
// controller.send('selectConsortium', '');
// assert.equal(controller.get('consortium').length,1);
// });

// test('should list ror id', function(assert) {
// let controller = this.owner.lookup('controller:providers.show.organizations.new');
// let model = {
// 'provider': make('provider'),
// 'organization': make('provider', { memberType: 'consortium_organization' }),
// };
// let ror = {
// 'id': 'https://ror.org/038sjwq14',
// 'name': 'Australian Research Data Commons',
// 'displayName': 'Australian Research Data Commons',
// };
// controller.set('model', model);
// controller.send('searchRor', ror.name); // what should be sent here
// assert.equal(controller.model.organization.get('organizations'), '');
// controller.send('selectRor', ror);
// assert.equal(controller.get('organizations').length,0); // why is organisations set to 0
// });
});

0 comments on commit 9bb32fd

Please sign in to comment.