diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index a05e50a..b50cd6b 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1103,7 +1103,7 @@ describe('index', () => { }); }); - it('rejects when response contains invalid password status code', async () => { + it('rejects when response contains update device messaging', async () => { options.failOnCompileError = true; mockDoPostRequest(`'Failed to check for software update'`, 200); @@ -1117,6 +1117,54 @@ describe('index', () => { } }); + it('rejects when response contains update device messaging and bad status code on first call', async () => { + options.failOnCompileError = true; + let spy = sinon.stub(rokuDeploy as any, 'doPostRequest').callsFake((params: any) => { + let results: any; + if (params?.formData['mysubmit'] === 'Replace') { + results = { response: { statusCode: 500 }, body: `'Failed to check for software update'` }; + } else { + results = { response: { statusCode: 200 }, body: `` }; + } + rokuDeploy['checkRequest'](results); + return Promise.resolve(results); + }); + + try { + await rokuDeploy.publish(options); + assert.fail('Should not have succeeded due to roku server compilation failure'); + } catch (err) { + expect(spy.callCount).to.eql(1); + expect((err as any).message).to.eql( + errors.UpdateCheckRequiredError.MESSAGE + ); + } + }); + + it('rejects when response contains update device messaging and bad status code on second call', async () => { + options.failOnCompileError = true; + let spy = sinon.stub(rokuDeploy as any, 'doPostRequest').callsFake((params: any) => { + let results: any; + if (params?.formData['mysubmit'] === 'Replace') { + results = { response: { statusCode: 500 }, body: `` }; + } else { + results = { response: { statusCode: 500 }, body: `'Failed to check for software update'` }; + } + rokuDeploy['checkRequest'](results); + return Promise.resolve(results); + }); + + try { + await rokuDeploy.publish(options); + assert.fail('Should not have succeeded due to roku server compilation failure'); + } catch (err) { + expect(spy.callCount).to.eql(2); + expect((err as any).message).to.eql( + errors.UpdateCheckRequiredError.MESSAGE + ); + } + }); + it('handles successful deploy', () => { options.failOnCompileError = true; mockDoPostRequest(); @@ -1208,13 +1256,38 @@ describe('index', () => { assert.fail('Should not have succeeded'); }); - it('Should throw an excpetion', async () => { + it('Should throw an exception and call doPost once', async () => { options.failOnCompileError = true; - mockDoPostRequest('', 577); + let spy = mockDoPostRequest('', 577); try { await rokuDeploy.publish(options); } catch (e) { + expect(spy.callCount).to.eql(1); + assert.ok('Exception was thrown as expected'); + expect(e).to.be.instanceof(errors.UpdateCheckRequiredError); + return; + } + assert.fail('Should not have succeeded'); + }); + + it('Should throw an exception and should call doPost twice', async () => { + options.failOnCompileError = true; + let spy = sinon.stub(rokuDeploy as any, 'doPostRequest').callsFake((params: any) => { + let results: any; + if (params?.formData['mysubmit'] === 'Replace') { + results = { response: { statusCode: 500 }, body: `'not an update error'` }; + } else { + results = { response: { statusCode: 577 }, body: `` }; + } + rokuDeploy['checkRequest'](results); + return Promise.resolve(results); + }); + + try { + await rokuDeploy.publish(options); + } catch (e) { + expect(spy.callCount).to.eql(2); assert.ok('Exception was thrown as expected'); expect(e).to.be.instanceof(errors.UpdateCheckRequiredError); return; @@ -3698,6 +3771,46 @@ describe('index', () => { }); }); + describe('isUpdateRequiredError', () => { + it('returns true if the status code is 577', () => { + expect( + rokuDeploy['isUpdateRequiredError']({ results: { response: { statusCode: 577 } } }) + ).to.be.true; + }); + + it('returns true if the body is an update response from device', () => { + const response = `\n
\n \n \n