Skip to content

Commit

Permalink
Merge pull request #180 from gregorylegarec/fix/service-error-message
Browse files Browse the repository at this point in the history
feat: revert service.terminate() error message + test for service.resizeClient() error
  • Loading branch information
doubleface authored Jun 15, 2017
2 parents d10f88d + ed28ace commit 60a9bc5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/intents.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function createService (cozy, intentId, serviceWindow) {
let terminated = false

const terminate = (message) => {
if (terminated) throw new Error('Intent service has been terminated')
if (terminated) throw new Error('Intent service has already been terminated')
terminated = true
serviceWindow.parent.postMessage(message, intent.attributes.client)
}
Expand Down
43 changes: 38 additions & 5 deletions test/unit/intents.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ describe('Intents', function () {
windowMock.parent.postMessage
.withArgs(messageMatch, expectedIntent.attributes.client).calledOnce.should.be.true()
})

it('should calculate width and height from a provided dom element', async function () {
const windowMock = mockWindow()

Expand Down Expand Up @@ -437,7 +438,39 @@ describe('Intents', function () {
windowMock.parent.postMessage
.withArgs(messageMatch, expectedIntent.attributes.client).calledOnce.should.be.true()
})

it('should not be called once the service has been terminated', async function () {
const windowMock = mockWindow()

const clientHandshakeEventMessageMock = {
origin: expectedIntent.attributes.client,
data: { foo: 'bar' }
}

const result = {
type: 'io.cozy.things'
}

windowMock.parent.postMessage.callsFake(() => {
const messageEventListener = windowMock.addEventListener.secondCall.args[1]
messageEventListener(clientHandshakeEventMessageMock)
})

const service = await cozy.client.intents.createService(expectedIntent._id, windowMock)

service.terminate(result)

should.throws(() => {
service.resizeClient({
element: {
clientHeight: 10,
clientWidth: 13
}
})
}, /Intent service has been terminated/)
})
})

describe('Terminate', function () {
it('should send result document to Client', async function () {
const windowMock = mockWindow()
Expand Down Expand Up @@ -524,7 +557,7 @@ describe('Intents', function () {

should.throws(() => {
service.terminate(result)
}, /Intent service has been terminated/)
}, /Intent service has already been terminated/)
})
})

Expand Down Expand Up @@ -596,7 +629,7 @@ describe('Intents', function () {

should.throws(() => {
service.cancel()
}, /Intent service has been terminated/)
}, /Intent service has already been terminated/)
})

it('should forbbid further calls to terminate()', async function () {
Expand All @@ -622,7 +655,7 @@ describe('Intents', function () {

should.throws(() => {
service.terminate(result)
}, /Intent service has been terminated/)
}, /Intent service has already been terminated/)
})
})

Expand Down Expand Up @@ -680,7 +713,7 @@ describe('Intents', function () {

should.throws(() => {
service.cancel()
}, /Intent service has been terminated/)
}, /Intent service has already been terminated/)
})

it('should forbbid further calls to terminate()', async function () {
Expand All @@ -706,7 +739,7 @@ describe('Intents', function () {

should.throws(() => {
service.terminate(result)
}, /Intent service has been terminated/)
}, /Intent service has already been terminated/)
})
})
})
Expand Down

0 comments on commit 60a9bc5

Please sign in to comment.