From 4391099864a32cccd85b88869c120c72fc5d2726 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Thu, 21 Sep 2017 20:04:29 +0300 Subject: [PATCH] *BREAKING*: Don't allow creating applications with discontinued device types Connects-To: #358 Change-Type: major --- lib/models/application.coffee | 15 +++++++++------ package.json | 2 +- tests/integration/models/application.spec.coffee | 6 +++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/models/application.coffee b/lib/models/application.coffee index 0caec36d0..0a29b5bfd 100644 --- a/lib/models/application.coffee +++ b/lib/models/application.coffee @@ -349,13 +349,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 {} @@ -365,7 +368,7 @@ getApplicationModel = (deps, opts) -> body: assign app_name: name - device_type: deviceSlug + device_type: deviceManifest.slug , extraOptions .asCallback(callback) diff --git a/package.json b/package.json index ee6352d55..4f4dbace2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/integration/models/application.spec.coffee b/tests/integration/models/application.spec.coffee index 7df9b3e0e..fd0e49401 100644 --- a/tests/integration/models/application.spec.coffee +++ b/tests/integration/models/application.spec.coffee @@ -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 ]) -> @@ -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