|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var EOL = require('os').EOL; |
| 4 | +var blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); |
| 5 | +var setupTestHooks = blueprintHelpers.setupTestHooks; |
| 6 | +var emberNew = blueprintHelpers.emberNew; |
| 7 | +var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; |
| 8 | +var emberGenerate = blueprintHelpers.emberGenerate; |
| 9 | + |
| 10 | +var expect = require('ember-cli-blueprint-test-helpers/chai').expect; |
| 11 | +var sleep = require('sleep'); |
| 12 | + |
| 13 | +describe('Acceptance: ember generate and destroy jsonapi-resource', function() { |
| 14 | + setupTestHooks(this); |
| 15 | + |
| 16 | + it('generates jsonapi-resource files (model, serializer, adapter, service, tests)', function() { |
| 17 | + var args = ['jsonapi-resource', 'foo']; |
| 18 | + |
| 19 | + return emberNew() |
| 20 | + .then(() => emberGenerateDestroy(args, (file) => { |
| 21 | + // model & unit test |
| 22 | + expect(file('app/models/foo.js')) |
| 23 | + .to.contain("import Ember from 'ember';"+EOL) |
| 24 | + .to.contain("import Resource from 'ember-jsonapi-resources/models/resource';"+EOL) |
| 25 | + .to.contain("import { attr, hasOne, hasMany } from 'ember-jsonapi-resources/models/resource';"+EOL); |
| 26 | + expect(file('tests/unit/models/foo-test.js')) |
| 27 | + .to.contain("import Ember from 'ember';"+EOL) |
| 28 | + .to.contain("import Model from '../../../models/foo';"+EOL) |
| 29 | + .to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL); |
| 30 | + |
| 31 | + // serializer and tests |
| 32 | + expect(file('app/serializers/foo.js')) |
| 33 | + .to.contain("import ApplicationSerializer from './application';"+EOL) |
| 34 | + .to.contain("export default ApplicationSerializer.extend({"+EOL) |
| 35 | + // we're not testing the body here |
| 36 | + .to.contain("});"+EOL); |
| 37 | + expect(file('tests/unit/serializers/foo-test.js')) |
| 38 | + .to.contain("import Ember from 'ember';"+EOL) |
| 39 | + .to.contain("import Resource from '../../../models/foo';"+EOL) |
| 40 | + .to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL); |
| 41 | + |
| 42 | + // adapter and tests |
| 43 | + expect(file('app/adapters/foo.js')) |
| 44 | + .to.contain("import ApplicationAdapter from './application';"+EOL) |
| 45 | + .to.contain("import config from '../config/environment';"+EOL) |
| 46 | + .to.contain("export default ApplicationAdapter.extend({"+EOL) |
| 47 | + // we're not testing the body here, except for type |
| 48 | + .to.contain("type: 'foo',"+EOL) |
| 49 | + .to.contain("});"+EOL); |
| 50 | + expect(file('tests/unit/adapters/foo-test.js')) |
| 51 | + .to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL); |
| 52 | + |
| 53 | + // service and tests |
| 54 | + expect(file('app/services/foos.js')) |
| 55 | + .to.contain("import Adapter from '../adapters/foo';"+EOL) |
| 56 | + .to.contain("import ServiceCache from '../mixins/service-cache';"+EOL) |
| 57 | + .to.contain("Adapter.reopenClass({ isServiceFactory: true });"+EOL) |
| 58 | + .to.contain("export default Adapter.extend(ServiceCache);"+EOL); |
| 59 | + expect(file('tests/unit/services/foos-test.js')) |
| 60 | + .to.contain("import { moduleFor, test } from 'ember-qunit';"+EOL); |
| 61 | + })); |
| 62 | + }); |
| 63 | +}); |
0 commit comments