Skip to content

Commit

Permalink
Merge pull request #398 from resin-io/358-discontinued-device-types
Browse files Browse the repository at this point in the history
Breaking: Don't allow creating devices with discontinued device types
  • Loading branch information
pimterry committed Oct 11, 2017
2 parents 56455c4 + 8a2b374 commit b63eab3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions lib/models/application.coffee
Expand Up @@ -341,13 +341,16 @@ getApplicationModel = (deps, opts) ->
else
Promise.resolve()

deviceSlugPromise = deviceModel().getDeviceSlug(deviceType)
.tap (deviceSlug) ->
if not deviceSlug?
deviceManifestPromise = deviceModel().getManifestBySlug(deviceType)
.tap (deviceManifest) ->
if not deviceManifest?
throw new errors.ResinInvalidDeviceType(deviceType)

return Promise.all([ deviceSlugPromise, parentAppPromise ])
.then ([ deviceSlug, parentApplication ]) ->
return Promise.all([ deviceManifestPromise, parentAppPromise ])
.then ([ deviceManifest, parentApplication ]) ->
if deviceManifest.state == 'DISCONTINUED'
throw new errors.ResinDiscontinuedDeviceType(deviceType)

extraOptions = if parentApplication
application: parentApplication.id
else {}
Expand All @@ -357,7 +360,7 @@ getApplicationModel = (deps, opts) ->
body:
assign
app_name: name
device_type: deviceSlug
device_type: deviceManifest.slug
, extraOptions
.asCallback(callback)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -71,7 +71,7 @@
"promise-memoize": "^1.2.0",
"resin-device-logs": "^3.1.0",
"resin-device-status": "^1.0.1",
"resin-errors": "^2.9.0",
"resin-errors": "^2.10.0",
"resin-pine": "^5.0.2",
"resin-register-device": "^4.0.1",
"resin-request": "^8.6.0",
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/application.spec.coffee
Expand Up @@ -36,7 +36,7 @@ describe 'Application Model', ->

it 'should be able to create a child application', ->
resin.models.application.create('FooBar', 'raspberry-pi').then (parentApplication) ->
resin.models.application.create('FooBarChild', 'edge', parentApplication.id)
resin.models.application.create('FooBarChild', 'generic-amd64', parentApplication.id)
.then ->
resin.models.application.getAll()
.then ([ parentApplication, childApplication ]) ->
Expand All @@ -46,6 +46,10 @@ describe 'Application Model', ->
promise = resin.models.application.create('FooBar', 'foobarbaz')
m.chai.expect(promise).to.be.rejectedWith('Invalid device type: foobarbaz')

it 'should be rejected if the device type is discontinuted', ->
promise = resin.models.application.create('FooBar', 'edge')
m.chai.expect(promise).to.be.rejectedWith('Discontinued device type: edge')

it 'should be rejected if the name has less than three characters', ->
promise = resin.models.application.create('Fo', 'raspberry-pi')
m.chai.expect(promise).to.be.rejected
Expand Down

0 comments on commit b63eab3

Please sign in to comment.