-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): arbitrary data can be attached to interactions reported i…
…n the test reports affects: @serenity-js/core, @serenity-js-examples/cucumber-domain-level-testing
- Loading branch information
Showing
32 changed files
with
531 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 17 additions & 10 deletions
27
...es/cucumber-domain-level-testing/features/support/screenplay/interactions/EnterOperand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { EnterOperandCommand, Operand } from '@serenity-js-examples/calculator-app'; | ||
import { Actor, Interaction } from '@serenity-js/core'; | ||
import { Actor, EmitArtifact, Interaction } from '@serenity-js/core'; | ||
import { JSONData } from '@serenity-js/core/lib/model'; | ||
import { InteractDirectly } from '../abilities'; | ||
|
||
export const EnterOperand = (operand: Operand) => Interaction.where(`#actor enters an operand of ${operand.value}`, (actor: Actor) => { | ||
const ability = InteractDirectly.as(actor); | ||
export const EnterOperand = (operand: Operand) => | ||
Interaction.where(`#actor enters an operand of ${operand.value}`, | ||
(actor: Actor, emitArtifact: EmitArtifact) => { | ||
const ability = InteractDirectly.as(actor); | ||
|
||
return ability.execute( | ||
new EnterOperandCommand( | ||
operand, | ||
ability.currentCalculationId(), | ||
), | ||
); | ||
}); | ||
const command = new EnterOperandCommand( | ||
operand, | ||
ability.currentCalculationId(), | ||
); | ||
|
||
ability.execute( | ||
command, | ||
); | ||
|
||
emitArtifact(JSONData.fromJSON(command.toJSON()), command.constructor.name); | ||
}); |
24 changes: 15 additions & 9 deletions
24
...les/cucumber-domain-level-testing/features/support/screenplay/interactions/UseOperator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { Operator, UseOperatorCommand } from '@serenity-js-examples/calculator-app'; | ||
import { Actor, Interaction } from '@serenity-js/core'; | ||
import { EnterOperandCommand, Operand, Operator, UseOperatorCommand } from '@serenity-js-examples/calculator-app'; | ||
import { Actor, EmitArtifact, Interaction } from '@serenity-js/core'; | ||
import { JSONData } from '@serenity-js/core/lib/model'; | ||
import { InteractDirectly } from '../abilities'; | ||
|
||
export const UseOperator = (operator: Operator) => Interaction.where(`#actor uses the ${ operator.constructor.name }`, (actor: Actor) => { | ||
const ability = InteractDirectly.as(actor); | ||
export const UseOperator = (operator: Operator) => Interaction.where(`#actor uses the ${ operator.constructor.name }`, | ||
(actor: Actor, emitArtifact: EmitArtifact) => { | ||
const ability = InteractDirectly.as(actor); | ||
|
||
return ability.execute( | ||
new UseOperatorCommand( | ||
const command = new UseOperatorCommand( | ||
operator, | ||
ability.currentCalculationId(), | ||
), | ||
); | ||
}); | ||
); | ||
|
||
ability.execute( | ||
command, | ||
); | ||
|
||
emitArtifact(JSONData.fromJSON(command.toJSON()), command.constructor.name); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,85 @@ | ||
import { Serialised } from 'tiny-types'; | ||
|
||
import { Artifact, FileType } from '../../src/io'; | ||
import { Name } from '../../src/model'; | ||
import { Artifact, JSONData, Name, Photo } from '../../src/model'; | ||
import { expect } from '../expect'; | ||
|
||
describe ('Artifact', () => { | ||
describe('Photo', () => { | ||
|
||
/** @test {Artifact} */ | ||
it('can be serialised and deserialised', () => { | ||
const photo = Photo.fromBase64('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEW01FWbeM52AAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg=='); | ||
|
||
const artifact = new Artifact( | ||
new Name('report'), | ||
FileType.JSON, | ||
{ some: 'report '}, | ||
); | ||
/** @test {Photo#toJSON} */ | ||
it('can be serialised', () => { | ||
const serialised = photo.toJSON(); | ||
|
||
expect(Artifact.fromJSON(artifact.toJSON() as Serialised<Artifact<any>>)).to.equal(artifact); | ||
expect(serialised.type).to.equal('Photo'); | ||
expect(serialised.base64EncodedValue).to.equal(photo.base64EncodedValue); | ||
}); | ||
|
||
/** | ||
* @test {Photo#toJSON} | ||
* @test {Artifact.fromJSON} | ||
*/ | ||
it('can be de-serialised', () => { | ||
const | ||
serialised = photo.toJSON(), | ||
deserialised = Artifact.fromJSON(serialised); | ||
|
||
expect(deserialised).to.equal(photo); | ||
}); | ||
|
||
/** | ||
* @test {Photo#map} | ||
* @test {Photo#base64EncodedValue} | ||
*/ | ||
it('allows for its value to be extracted as a Buffer', () => { | ||
photo.map(value => expect(value).to.be.instanceOf(Buffer)); | ||
photo.map(value => expect(value.toString('base64')).to.equal(photo.base64EncodedValue)); | ||
}); | ||
|
||
/** | ||
* @test {Photo.fromBuffer} | ||
*/ | ||
it('can be instantiated from a Buffer', () => { | ||
expect(Photo.fromBuffer(Buffer.from(photo.base64EncodedValue, 'base64'))).to.equal(photo); | ||
}); | ||
}); | ||
|
||
describe('JSONData', () => { | ||
|
||
const json = JSONData.fromJSON({ | ||
key: ['v', 'a', 'l', 'u', 'e'], | ||
}); | ||
|
||
/** @test {JSONData#toJSON} */ | ||
it('can be serialised', () => { | ||
const serialised = json.toJSON(); | ||
|
||
expect(serialised.type).to.equal('JSONData'); | ||
expect(serialised.base64EncodedValue).to.equal(json.base64EncodedValue); | ||
}); | ||
|
||
/** | ||
* @test {JSONData#toJSON} | ||
* @test {Artifact.fromJSON} | ||
*/ | ||
it('can be de-serialised', () => { | ||
const | ||
serialised = json.toJSON(), | ||
deserialised = Artifact.fromJSON(serialised); | ||
|
||
expect(deserialised).to.equal(json); | ||
}); | ||
|
||
/** | ||
* @test {JSONData#map} | ||
* @test {JSONData#base64EncodedValue} | ||
*/ | ||
it('allows for its value to be extracted as a JSON value', () => { | ||
json.map(value => expect(value).to.be.instanceOf(Object)); | ||
json.map(value => expect(value).to.deep.equal({ | ||
key: ['v', 'a', 'l', 'u', 'e'], | ||
})); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'mocha'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { Actor, EmitArtifact, Interaction } from '../../src/screenplay'; | ||
|
||
import { JSONData } from '../../src/model/artifacts'; | ||
import { expect } from '../expect'; | ||
|
||
describe('Interaction', () => { | ||
|
||
const Ivonne = Actor.named('Ivonne'); | ||
|
||
describe('when defining an interaction', () => { | ||
|
||
/** @test {Interaction} */ | ||
it(`provides a convenient factory method for synchronous interactions`, () => { | ||
const spy = sinon.spy(); | ||
|
||
const InteractWithTheSystem = () => Interaction.where(`#actor interacts with the system`, (actor: Actor) => { | ||
spy(actor); | ||
}); | ||
|
||
return expect(Ivonne.attemptsTo( | ||
InteractWithTheSystem(), | ||
)) | ||
.to.be.fulfilled | ||
.then(() => { | ||
expect(spy).to.have.been.calledWith(Ivonne); | ||
}); | ||
}); | ||
|
||
/** @test {Interaction} */ | ||
it(`provides a convenient factory method for asynchronous interactions`, () => { | ||
const spy = sinon.spy(); | ||
|
||
const InteractWithTheSystem = () => Interaction.where(`#actor interacts with the system`, (actor: Actor) => { | ||
spy(actor); | ||
|
||
return Promise.resolve(); | ||
}); | ||
|
||
return expect(Ivonne.attemptsTo( | ||
InteractWithTheSystem(), | ||
)) | ||
.to.be.fulfilled | ||
.then(() => { | ||
expect(spy).to.have.been.calledWith(Ivonne); | ||
}); | ||
}); | ||
}); | ||
|
||
/** @test {Interaction} */ | ||
it('can optionally emit an artifact to be attached to the report or stored', () => { | ||
const spy = sinon.spy(); | ||
|
||
const InteractWithTheSystem = () => Interaction.where(`#actor interacts with the system`, (actor: Actor, emitArtifact: EmitArtifact) => { | ||
spy(actor); | ||
|
||
emitArtifact(JSONData.fromJSON({ token: '123' }), 'Session Token'); | ||
}); | ||
|
||
return expect(Ivonne.attemptsTo( | ||
InteractWithTheSystem(), | ||
)) | ||
.to.be.fulfilled | ||
.then(() => { | ||
expect(spy).to.have.been.calledWith(Ivonne); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.