<commit_before>m = require('mochainon')
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
utils = require('../lib/utils')

describe 'Utils:', ->

	describe '.getConfigPartitionInformationByType()', ->

		describe 'given a raspberry-pi manifest', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.withArgs('raspberry-pi').returns Promise.resolve
					configuration:
						config:
							partition:
								primary: 4
								logical: 1
							path: '/config.json'

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should eventually become the configuration information', ->
				promise = utils.getConfigPartitionInformationByType('raspberry-pi')
				m.chai.expect(promise).to.eventually.become
					partition: 5
					path: '/config.json'

		describe 'given an edison manifest', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.withArgs('edison').returns Promise.resolve
					configuration:
						config:
							image: 'config.img'
							path: '/config.json'

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should eventually become the configuration information', ->
				promise = utils.getConfigPartitionInformationByType('edison')
				m.chai.expect(promise).to.eventually.become
					image: 'config.img'
					path: '/config.json'

		describe 'given a device type manifest without a configuration property', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.returns(Promise.resolve({}))

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should be rejected with an error', ->
				promise = utils.getConfigPartitionInformationByType('foobar')
				m.chai.expect(promise).to.be.rejectedWith('Unsupported device type: foobar')

		describe 'given a device type manifest without a configuration.config property', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.returns(Promise.resolve(configuration: {}))

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should be rejected with an error', ->
				promise = utils.getConfigPartitionInformationByType('foobar')
				m.chai.expect(promise).to.be.rejectedWith('Unsupported device type: foobar')<commit_msg>Add a test for the new format partition manifest<commit_after>m = require('mochainon')
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
utils = require('../lib/utils')

describe 'Utils:', ->

	describe '.getConfigPartitionInformationByType()', ->

		describe 'given a raspberry-pi manifest', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.withArgs('raspberry-pi').returns Promise.resolve
					configuration:
						config:
							partition:
								primary: 4
								logical: 1
							path: '/config.json'

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should eventually become the configuration information', ->
				promise = utils.getConfigPartitionInformationByType('raspberry-pi')
				m.chai.expect(promise).to.eventually.become
					partition: 5
					path: '/config.json'

		describe 'given an edison manifest', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.withArgs('edison').returns Promise.resolve
					configuration:
						config:
							image: 'config.img'
							path: '/config.json'

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should eventually become the configuration information', ->
				promise = utils.getConfigPartitionInformationByType('edison')
				m.chai.expect(promise).to.eventually.become
					image: 'config.img'
					path: '/config.json'

		describe 'given a device type manifest without a configuration property', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.returns(Promise.resolve({}))

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should be rejected with an error', ->
				promise = utils.getConfigPartitionInformationByType('foobar')
				m.chai.expect(promise).to.be.rejectedWith('Unsupported device type: foobar')

		describe 'given a device type manifest with a new format partition identifier', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.withArgs('raspberry-pi').returns Promise.resolve
					configuration:
						config:
							partition: 5
							path: '/config.json'

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should eventually become the configuration information', ->
				promise = utils.getConfigPartitionInformationByType('raspberry-pi')
				m.chai.expect(promise).to.eventually.become
					partition: 5
					path: '/config.json'

		describe 'given a device type manifest without a configuration.config property', ->

			beforeEach ->
				@getManifestBySlugStub = m.sinon.stub(resin.models.device, 'getManifestBySlug')
				@getManifestBySlugStub.returns(Promise.resolve(configuration: {}))

			afterEach ->
				@getManifestBySlugStub.restore()

			it 'should be rejected with an error', ->
				promise = utils.getConfigPartitionInformationByType('foobar')
				m.chai.expect(promise).to.be.rejectedWith('Unsupported device type: foobar')
{'fraction_non_alphanumeric': 0.11828150278626641, 'fraction_numerical': 0.0014380729822038468, 'mean_word_length': 3.902202643171806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192341', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1711, 'n_words': 329}