Added new matcher for location strings

- Often in our API we want to check that the location string looks roughly right for a resource
- At the moment we're matching any String, this upgrades the check to look for resource URLs
This commit is contained in:
Hannah Wolfe 2022-02-16 12:50:58 +00:00
parent bed0115ddd
commit 6a2755893e
No known key found for this signature in database
GPG Key ID: AB586C3B5AE5C037
5 changed files with 15 additions and 12 deletions

View File

@ -850,7 +850,7 @@ Object {
"content-length": "588",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": Any<String>,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/members\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}
@ -964,7 +964,7 @@ Object {
"content-length": "424",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": Any<String>,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/members\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}
@ -1320,7 +1320,7 @@ Object {
"content-length": "431",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": Any<String>,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/members\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}
@ -1411,7 +1411,7 @@ Object {
"content-length": "442",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": Any<String>,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/members\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}

View File

@ -1,5 +1,5 @@
const {agentProvider, mockManager, fixtureManager, matchers} = require('../../utils/e2e-framework');
const {anyEtag, anyObjectId, anyUuid, anyDate, anyString, anyArray} = matchers;
const {anyEtag, anyObjectId, anyUuid, anyDate, anyString, anyArray, anyLocationFor} = matchers;
const nock = require('nock');
const should = require('should');
@ -176,7 +176,7 @@ describe('Members API', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
location: anyString //TODO: validate the exact string?
location: anyLocationFor('members')
});
await agent
@ -249,7 +249,7 @@ describe('Members API', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
location: anyString //TODO: validate the exact string?
location: anyLocationFor('members')
});
const newMember = body.members[0];
@ -304,7 +304,7 @@ describe('Members API', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
location: anyString //TODO: validate the exact string?
location: anyLocationFor('members')
});
const newMember = body.members[0];
@ -350,7 +350,7 @@ describe('Members API', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
location: anyString //TODO: validate the exact string?
location: anyLocationFor('members')
});
const newMember = body.members[0];

View File

@ -827,7 +827,7 @@ Object {
"content-length": "457",
"content-type": "application/json; charset=utf-8",
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"location": Any<String>,
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/members\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
"vary": "Origin, Accept-Encoding",
"x-powered-by": "Express",
}

View File

@ -1,7 +1,7 @@
const assert = require('assert');
const nock = require('nock');
const {agentProvider, mockManager, fixtureManager, matchers} = require('../../../utils/e2e-framework');
const {anyString, anyArray, anyObjectId, anyEtag, anyUuid, anyErrorId, anyDate} = matchers;
const {anyString, anyArray, anyObjectId, anyEtag, anyUuid, anyErrorId, anyDate, anyLocationFor} = matchers;
let agent;
@ -98,7 +98,7 @@ describe('Members API', function () {
})
.matchHeaderSnapshot({
etag: anyEtag,
location: anyString
location: anyLocationFor('members')
});
mockManager.assert.sentEmail({

View File

@ -221,6 +221,9 @@ module.exports = {
anyObjectId: stringMatching(/[a-f0-9]{24}/),
anyErrorId: stringMatching(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/),
anyUuid: stringMatching(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/),
anyLocationFor: (resource) => {
return stringMatching(new RegExp(`https?://.*?/${resource}/[a-f0-9]{24}/`));
},
stringMatching
}
};