Skip to content
Permalink
Browse files
fix(rest): Descriptions of HTTPRequests are more human-friendly, and …
…so is the description of the Lo
  • Loading branch information
jan-molak committed Feb 13, 2019
1 parent ca4d6ac commit 2368ebae9df5c18e6052c50a2ebd758e21b3dd0a
@@ -45,8 +45,8 @@ describe('@serenity-js/local-server', () => {
Pick.from(events)
.next(ActivityStarts, hasName(`Nadia starts the local server`))
.next(ActivityFinished, hasName(`Nadia starts the local server`))
.next(ActivityFinished, hasName(`Nadia ensures that URL of the local server does start with 'http://127.0.0.1'`))
.next(ActivityFinished, hasName(`Nadia sends a GET request`))
.next(ActivityFinished, hasName(`Nadia ensures that the URL of the local server does start with 'http://127.0.0.1'`))
.next(ActivityFinished, hasName(`Nadia sends a GET request to the URL of the local server`))
.next(ActivityFinished, hasName(`Nadia ensures that the status of the last response does equal 200`))
.next(ActivityFinished, hasName(`Nadia ensures that the body of the last response does equal 'Hello World!'`))
.next(ActivityStarts, hasName(`Nadia stops the local server`))
@@ -9,7 +9,7 @@ export class LocalServer {
* @returns {Question<string>} Url of the locally running Node.js server
*/
static url() {
return Question.about<string>('URL of the local server', actor => {
return Question.about<string>('the URL of the local server', actor => {
return ManageALocalServer.as(actor).mapInstance(server => {
const info = server.address();

@@ -34,4 +34,10 @@ describe('DeleteRequest', () => {
Authorization: 'token',
},
}));

/** @test {DeleteRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(DeleteRequest.to('/products/2').toString())
.to.equal(`a DELETE request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { GetRequest } from '../../src/model';
import { DeleteRequest, GetRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {GetRequest} */
@@ -34,4 +34,10 @@ describe('GetRequest', () => {
Accept: 'application/json',
},
}));

/** @test {GetRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(GetRequest.to('/products/2').toString())
.to.equal(`a GET request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { HeadRequest } from '../../src/model';
import { GetRequest, HeadRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {HeadRequest} */
@@ -34,4 +34,10 @@ describe('HeadRequest', () => {
Accept: 'application/json',
},
}));

/** @test {HeadRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(HeadRequest.to('/products/2').toString())
.to.equal(`a HEAD request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { OptionsRequest } from '../../src/model';
import { HeadRequest, OptionsRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {OptionsRequest} */
@@ -34,4 +34,10 @@ describe('OptionsRequest', () => {
Accept: 'application/json',
},
}));

/** @test {Options#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(OptionsRequest.to('/products/2').toString())
.to.equal(`an OPTIONS request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { PatchRequest } from '../../src/model';
import { OptionsRequest, PatchRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {PatchRequest} */
@@ -48,4 +48,10 @@ describe('PatchRequest', () => {
},
data: { name: 'apple' },
}));

/** @test {PatchRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(PatchRequest.to('/products/2').toString())
.to.equal(`a PATCH request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { PostRequest } from '../../src/model';
import { OptionsRequest, PostRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {PostRequest} */
@@ -39,4 +39,10 @@ describe('PostRequest', () => {
},
data: { name: 'apple' },
}));

/** @test {PostRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(PostRequest.to('/products/2').toString())
.to.equal(`a POST request to '/products/2'`);
});
});
@@ -1,7 +1,7 @@
import 'mocha';

import { Actor } from '@serenity-js/core';
import { PutRequest } from '../../src/model';
import { PostRequest, PutRequest } from '../../src/model';
import { expect } from '../expect';

/** @test {PutRequest} */
@@ -48,4 +48,10 @@ describe('PutRequest', () => {
},
data: { name: 'apple' },
}));

/** @test {PutRequest#toString} */
it(`provides a sensible description of the interaction being performed`, () => {
expect(PutRequest.to('/products/2').toString())
.to.equal(`a PUT request to '/products/2'`);
});
});
@@ -1,4 +1,5 @@
import { AnswersQuestions, KnowableUnknown, Question, UsesAbilities } from '@serenity-js/core';
import { formatted } from '@serenity-js/core/lib/io';
import { AxiosRequestConfig } from 'axios';

/**
@@ -61,7 +62,7 @@ export abstract class HTTPRequest implements Question<Promise<AxiosRequestConfig
}

toString() {
return `a ${ this.httpMethodName() } request`;
return `${ this.requestDescription() } to ${ formatted `${ this.resourceUri }` }`;
}

/**
@@ -74,4 +75,18 @@ export abstract class HTTPRequest implements Question<Promise<AxiosRequestConfig
private httpMethodName(): string {
return this.constructor.name.replace(/Request/, '').toUpperCase();
}

/**
* @desc
* A human-readable description of the request, such as "a GET request", "an OPTIONS request", etc.
*
* @private
*/
private requestDescription(): string {
const
vowels = [ 'A', 'E', 'I', 'O', 'U' ],
method = this.httpMethodName();

return `${ ~vowels.indexOf(method[0]) ? 'an' : 'a' } ${ method } request`;
}
}

0 comments on commit 2368eba

Please sign in to comment.