-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Adds ember-data blueprints for Consul specific HTTP adapter etc (#…
…6461) * ui: Adds ember-data blueprints for Consul specific HTTP adapter etc These are currently quite Consul specific, but we also overwrite the default model-test blueprint to keep the names consistent (dasherized) for easy test filtering. ``` ember generate [adapter|serializer|model|repository|route] <name> ```
- Loading branch information
Showing
22 changed files
with
591 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*eslint node/no-extraneous-require: "off"*/ | ||
'use strict'; | ||
|
||
const useTestFrameworkDetector = require('@ember-data/-build-infra/src/utilities/test-framework-detector'); | ||
const path = require('path'); | ||
|
||
module.exports = useTestFrameworkDetector({ | ||
description: 'Generates a Consul HTTP ember-data adapter unit and integration tests', | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
return { | ||
__root__() { | ||
return 'tests'; | ||
}, | ||
__path__() { | ||
return ''; | ||
} | ||
}; | ||
}, | ||
|
||
locals(options) { | ||
return { | ||
}; | ||
}, | ||
}); |
36 changes: 36 additions & 0 deletions
36
ui-v2/blueprints/adapter-test/qunit-files/__root__/__path__/integration/adapters/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Integration | Adapter | <%= dasherizedModuleName %>', function(hooks) { | ||
setupTest(hooks); | ||
const dc = 'dc-1'; | ||
const id = 'slug'; | ||
test('requestForQuery returns the correct url/method', function(assert) { | ||
const adapter = this.owner.lookup('adapter:<%= dasherizedModuleName %>'); | ||
const client = this.owner.lookup('service:client/http'); | ||
const expected = `GET /v1/<%= dasherizedModuleName %>?dc=${dc}`; | ||
const actual = adapter.requestForQuery(client.url, { | ||
dc: dc, | ||
}); | ||
assert.equal(actual, expected); | ||
}); | ||
test('requestForQueryRecord returns the correct url/method', function(assert) { | ||
const adapter = this.owner.lookup('adapter:<%= dasherizedModuleName %>'); | ||
const client = this.owner.lookup('service:client/http'); | ||
const expected = `GET /v1/<%= dasherizedModuleName %>/${id}?dc=${dc}`; | ||
const actual = adapter.requestForQueryRecord(client.url, { | ||
dc: dc, | ||
id: id, | ||
}); | ||
assert.equal(actual, expected); | ||
}); | ||
test("requestForQueryRecord throws if you don't specify an id", function(assert) { | ||
const adapter = this.owner.lookup('adapter:<%= dasherizedModuleName %>'); | ||
const client = this.owner.lookup('service:client/http'); | ||
assert.throws(function() { | ||
adapter.requestForQueryRecord(client.url, { | ||
dc: dc, | ||
}); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
ui-v2/blueprints/adapter-test/qunit-files/__root__/__path__/unit/adapters/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Adapter | <%= dasherizedModuleName %>', function(hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let adapter = this.owner.lookup('adapter:<%= dasherizedModuleName %>'); | ||
assert.ok(adapter); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
ui-v2/blueprints/adapter/files/__root__/__path__/__name__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Adapter from './application'; | ||
|
||
export default Adapter.extend({ | ||
requestForQuery: function(request, { dc, index }) { | ||
return request` | ||
GET /v1/<%= dasherizedModuleName %>?${{ dc }} | ||
${{ index }} | ||
`; | ||
}, | ||
requestForQueryRecord: function(request, { dc, index, id }) { | ||
if (typeof id === 'undefined') { | ||
throw new Error('You must specify an id'); | ||
} | ||
return request` | ||
GET /v1/<%= dasherizedModuleName %>/${id}?${{ dc }} | ||
${{ index }} | ||
`; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*eslint node/no-extraneous-require: "off"*/ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification').isModuleUnificationProject; | ||
module.exports = { | ||
description: 'Generates a Consul HTTP ember-data adapter', | ||
|
||
availableOptions: [{ name: 'base-class', type: String }], | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
if (isModuleUnificationProject(this.project)) { | ||
return { | ||
__root__() { | ||
return 'src'; | ||
}, | ||
__path__(options) { | ||
return path.join('data', 'models', options.dasherizedModuleName); | ||
}, | ||
__name__() { | ||
return 'adapter'; | ||
}, | ||
}; | ||
} | ||
}, | ||
locals(options) { | ||
// Return custom template variables here. | ||
return { | ||
}; | ||
} | ||
|
||
// afterInstall(options) { | ||
// // Perform extra work here. | ||
// } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*eslint node/no-extraneous-require: "off"*/ | ||
'use strict'; | ||
|
||
const useTestFrameworkDetector = require('@ember-data/-build-infra/src/utilities/test-framework-detector'); | ||
const path = require('path'); | ||
|
||
module.exports = useTestFrameworkDetector({ | ||
description: 'Generates a Consul ember-data model unit tests', | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
return { | ||
__root__() { | ||
return 'tests'; | ||
}, | ||
__path__() { | ||
return ''; | ||
} | ||
}; | ||
}, | ||
|
||
locals(options) { | ||
return { | ||
}; | ||
}, | ||
}); |
13 changes: 13 additions & 0 deletions
13
ui-v2/blueprints/model-test/qunit-files/__root__/__path__/unit/models/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Model | <%= dasherizedModuleName %>', function(hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let model = store.createRecord('<%= dasherizedModuleName %>', {}); | ||
assert.ok(model); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
ui-v2/blueprints/model/files/__root__/__path__/__name__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Model from 'ember-data/model'; | ||
import attr from 'ember-data/attr'; | ||
|
||
export const PRIMARY_KEY = 'uid'; | ||
export const SLUG_KEY = 'ID'; | ||
export default Model.extend({ | ||
[PRIMARY_KEY]: attr('string'), | ||
[SLUG_KEY]: attr('string'), | ||
Datacenter: attr('string'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*eslint node/no-extraneous-require: "off"*/ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const isModuleUnificationProject = require('@ember-data/-build-infra/src/utilities/module-unification').isModuleUnificationProject; | ||
module.exports = { | ||
description: 'Generates a Consul HTTP ember-data model', | ||
|
||
availableOptions: [], | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
if (isModuleUnificationProject(this.project)) { | ||
return { | ||
__root__() { | ||
return 'src'; | ||
}, | ||
__path__(options) { | ||
return path.join('data', 'models', options.dasherizedModuleName); | ||
}, | ||
__name__() { | ||
return 'model'; | ||
}, | ||
}; | ||
} | ||
}, | ||
locals(options) { | ||
// Return custom template variables here. | ||
return { | ||
}; | ||
} | ||
|
||
// afterInstall(options) { | ||
// // Perform extra work here. | ||
// } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*eslint node/no-extraneous-require: "off"*/ | ||
'use strict'; | ||
|
||
const useTestFrameworkDetector = require('@ember-data/-build-infra/src/utilities/test-framework-detector'); | ||
const path = require('path'); | ||
|
||
module.exports = useTestFrameworkDetector({ | ||
description: 'Generates a Consul HTTP ember-data serializer unit and integration tests', | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
return { | ||
__root__() { | ||
return 'tests'; | ||
}, | ||
__path__() { | ||
return ''; | ||
} | ||
}; | ||
}, | ||
|
||
locals(options) { | ||
return { | ||
screamingSnakeCaseModuleName: options.entity.name.replace('-', '_').toUpperCase() | ||
}; | ||
}, | ||
}); |
75 changes: 75 additions & 0 deletions
75
...repository-test/qunit-files/__root__/__path__/integration/services/repository/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
import repo from 'consul-ui/tests/helpers/repo'; | ||
|
||
moduleFor('service:repository/<%= dasherizedModuleName %>', 'Integration | Repository | <%= dasherizedModuleName %>', { | ||
// Specify the other units that are required for this test. | ||
integration: true, | ||
}); | ||
const dc = 'dc-1'; | ||
const id = 'slug'; | ||
const now = new Date().getTime(); | ||
test('findByDatacenter returns the correct data for list endpoint', function(assert) { | ||
get(this.subject(), 'store').serializerFor('<%= dasherizedModuleName %>').timestamp = function() { | ||
return now; | ||
}; | ||
return repo( | ||
'Service', | ||
'findAllByDatacenter', | ||
this.subject(), | ||
function retrieveStub(stub) { | ||
return stub(`/v1/<%= dasherizedModuleName %>?dc=${dc}`, { | ||
CONSUL_<%= screamingSnakeCaseModuleName %>_COUNT: '100', | ||
}); | ||
}, | ||
function performTest(service) { | ||
return service.findAllByDatacenter(dc); | ||
}, | ||
function performAssertion(actual, expected) { | ||
assert.deepEqual( | ||
actual, | ||
expected(function(payload) { | ||
return payload.map(item => | ||
Object.assign({}, item, { | ||
SyncTime: now, | ||
Datacenter: dc, | ||
uid: `["${dc}","${item.Name}"]`, | ||
}) | ||
); | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
test('findBySlug returns the correct data for item endpoint', function(assert) { | ||
return repo( | ||
'Service', | ||
'findBySlug', | ||
this.subject(), | ||
function retrieveStub(stub) { | ||
return stub(`/v1/<%= dasherizedModuleName %>/${id}?dc=${dc}`, { | ||
CONSUL_<%= screamingSnakeCaseModuleName %>_COUNT: 1, | ||
}); | ||
}, | ||
function performTest(service) { | ||
return service.findBySlug(id, dc); | ||
}, | ||
function performAssertion(actual, expected) { | ||
assert.deepEqual( | ||
actual, | ||
expected(function(payload) { | ||
return Object.assign( | ||
{}, | ||
{ | ||
Datacenter: dc, | ||
uid: `["${dc}","${id}"]`, | ||
meta: { | ||
cursor: undefined | ||
} | ||
}, | ||
payload | ||
); | ||
}) | ||
); | ||
} | ||
); | ||
}); |
12 changes: 12 additions & 0 deletions
12
...prints/repository-test/qunit-files/__root__/__path__/unit/services/repository/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Repository | <%= dasherizedModuleName %>', function(hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let repo = this.owner.lookup('service:repository/<%= dasherizedModuleName %>'); | ||
assert.ok(repo); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
ui-v2/blueprints/repository/files/__root__/__path__/__name__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import RepositoryService from 'consul-ui/services/repository'; | ||
|
||
const modelName = '<%= dasherizedModuleName %>'; | ||
export default RepositoryService.extend({ | ||
getModelName: function() { | ||
return modelName; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
module.exports = { | ||
description: 'Generates a Consul repository', | ||
|
||
availableOptions: [], | ||
|
||
root: __dirname, | ||
|
||
fileMapTokens(options) { | ||
return { | ||
__path__() { | ||
return path.join('services', 'repository'); | ||
} | ||
}; | ||
}, | ||
locals(options) { | ||
// Return custom template variables here. | ||
return { | ||
}; | ||
} | ||
|
||
// afterInstall(options) { | ||
// // Perform extra work here. | ||
// } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
}); |
1 change: 1 addition & 0 deletions
1
ui-v2/blueprints/route/files/__root__/__templatepath__/__templatename__.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
Oops, something went wrong.