Skip to content

Commit

Permalink
Merge 04a9f17 into 5f411ef
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-molak committed May 18, 2024
2 parents 5f411ef + 04a9f17 commit 450b968
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Enter', () => {

it('provides a sensible and masked description of the interaction being performed', () => {
expect(Enter.theValue(Masked.valueOf(actorCalled('Bernie').name)).into(Form.field).toString())
.to.equal(`#actor enters '[a masked value]' into the name field`);
.to.equal(`#actor enters '[MASKED]' into the name field`);
});

it('correctly detects its invocation location', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/spec/screenplay/questions/Masked.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ describe('Masked', () => {
it('should return the sensitive value when answered by an actor', async () => {
const sensitiveValue = 'your_masked_value';
const answer = await Masked.valueOf(sensitiveValue).answeredBy(Fiona);

expect(answer).to.equal(sensitiveValue);
});

it('should return masked value in description when using valueOf', async () => {
const sensitiveValue = 'your_masked_value';
const maskedDescription = Masked.valueOf(sensitiveValue).toString();
expect(maskedDescription).to.equal('[a masked value]');

expect(maskedDescription).to.equal('[MASKED]');
});
});
30 changes: 26 additions & 4 deletions packages/core/src/screenplay/questions/Masked.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { UsesAbilities } from '../abilities';
import { type Answerable } from '../Answerable';
import { Question, type QuestionAdapter } from '../Question';
import { Question } from '../Question';
import type { AnswersQuestions } from './AnswersQuestions';

/**
* This question masks sensitive data handled by the actors and prevents
Expand All @@ -12,7 +14,27 @@ import { Question, type QuestionAdapter } from '../Question';
*
* @group Questions
*/
export class Masked {
export class Masked extends Question<Promise<string>> {

private subject: string;

private constructor(private readonly value: Answerable<string>) {
super();
this.subject = `[MASKED]`;
}

toString(): string {
return this.subject;
}

describedAs(subject: string): this {
this.subject = subject;
return this;
}

answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<string> {
return actor.answer(this.value);
}

/**
* Retrieves the value of a sensitive parameter and mask it in any report.
Expand All @@ -32,7 +54,7 @@ export class Masked {
* @param parameter - An {@link Answerable} representing the masked value.
* @returns A {@link QuestionAdapter} representing the masked value.
*/
static valueOf(parameter: Answerable<string>): QuestionAdapter<string> {
return Question.about('[a masked value]', async actor => actor.answer(parameter));
static valueOf(parameter: Answerable<string>): Question<Promise<string>> {
return new Masked(parameter);
}
}
2 changes: 1 addition & 1 deletion packages/web/src/screenplay/interactions/Enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { PageElementInteraction } from './PageElementInteraction';
* Enter.theValue(Masked.valueOf('your little secret').into(Form.exampleInputField()),
* )
*
* // Gets reported as: "Esme enters [a masked value] into the example input field"
* // Gets reported as: "Esme enters [MASKED] into the example input field"
* ```
*
* ## Learn more
Expand Down

0 comments on commit 450b968

Please sign in to comment.