From 36c0e8b31cf15c2bf4e1df59d8fa5d9710ee1adf Mon Sep 17 00:00:00 2001 From: DevSide Date: Fri, 15 Nov 2024 13:10:02 +0100 Subject: [PATCH] refactor: body tests in yml --- packages/dynamock/test/integrations.spec.ts | 76 ------- .../body/matching-body-array-strict.yml | 22 +++ .../matching/body/matching-body-array.yml | 57 ++++++ .../body/matching-body-object-strict.yml | 86 ++++++++ .../matching/body/matching-body-object.yml | 185 ++++++++++++++++++ .../matching/body/matching-body-regex.yml | 164 ++++++++++++++++ .../matching/body/matching-body-string.yml | 38 ++++ .../body/no-matching-body-array-strict.yml | 22 +++ .../matching/body/no-matching-body-array.yml | 19 ++ .../body/no-matching-body-object-strict.yml | 34 ++++ .../matching/body/no-matching-body-object.yml | 45 +++++ .../matching/body/no-matching-body-regex.yml | 22 +++ 12 files changed, 694 insertions(+), 76 deletions(-) create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-array-strict.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-array.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-object-strict.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-object.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-regex.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/matching-body-string.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array-strict.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object-strict.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object.yml create mode 100644 packages/test-cases/test-files/fixtures/matching/body/no-matching-body-regex.yml diff --git a/packages/dynamock/test/integrations.spec.ts b/packages/dynamock/test/integrations.spec.ts index 8c0e071..ce86399 100644 --- a/packages/dynamock/test/integrations.spec.ts +++ b/packages/dynamock/test/integrations.spec.ts @@ -155,82 +155,6 @@ describe('integrations.js', () => { }) }) - describe('matching body', () => { - test.each([ - [null, {}, {}, null, true], - [null, [], {}, null, true], - [null, {}, [], null, true], - [null, [], [], null, true], - [null, '', '', null, true], - [null, { x: null }, { x: null }, null, true], - [null, ['a', 'b'], ['a', 'b'], null, true], - [null, ['a', 'b'], ['a', 'b'], { strict: true }, true], - [null, ['a', 'b'], ['a', 'b'], { allowRegex: true }, true], - [null, ['a', 'b'], ['b', 'a'], null, false], - [null, ['a', 'b'], ['b', 'a'], { allowRegex: true }, false], - [null, ['a', 'b'], ['b', 'a'], { strict: true }, false], - [null, {}, { x: 'x' }, null, true], - [null, {}, { x: 'x' }, { allowRegex: true }, true], - [null, {}, { x: 'x' }, { strict: true }, false], - [null, { x: 'x' }, { x: 'x' }, null, true], - [null, { x: 'x' }, { x: 'x' }, { allowRegex: true }, true], - [null, { x: '/x/' }, { x: 'x' }, { allowRegex: true }, true], - [null, { x: 'x' }, { x: 'x' }, { strict: true }, true], - [null, { x: 'x' }, { x: 'x', other: 'other' }, null, true], - [null, { x: 'x' }, { x: 'x', other: 'other' }, { allowRegex: true }, true], - [null, { x: '/X/i' }, { x: 'x', other: 'other' }, { allowRegex: true }, true], - [null, { x: 'x' }, { x: 'x', other: 'other' }, { strict: true }, false], - [null, { x: 'x', other: 'other' }, { x: 'x' }, null, false], - [null, { a: { b: 'b' } }, { a: { b: 'b', c: 'c' } }, null, true], - [null, { a: { b: 'b', c: [] } }, { a: { b: 'b', c: [] } }, null, true], - [null, { a: { b: 'b', c: [] } }, { a: { b: 'b', c: [] } }, { allowRegex: true }, true], - [null, { a: { b: '/B/i', c: [] } }, { a: { b: 'b', c: [] } }, { allowRegex: true }, true], - [null, { a: { b: 'b', c: [] } }, { a: { b: 'b', c: [] } }, { strict: true }, true], - [null, { a: { b: 'b', c: {} } }, { a: { b: 'b', c: [] } }, null, false], - [null, { a: { b: 'b', c: {} } }, { a: { b: 'b' } }, null, false], - ])( - 'match body config="%o" matchValues="%s" values="%o" options="%o" shouldMatch=%s', - async (configuration, matchValues, values, options, shouldMatch) => { - const path = '/test' - const method = 'post' - - if (configuration) { - await request - .put('/___config') - .send({ - body: configuration, - }) - .expect(200) - } - - await request - .post('/___fixtures') - .send({ - request: { - path, - method, - body: matchValues, - ...(options - ? { - options: { - body: options, - }, - } - : {}), - }, - response: { - body: {}, - }, - }) - .expect(201) - - await request[method](path) - .send(values) - .expect(shouldMatch ? 200 : 404) - }, - ) - }) - describe('lifetime option', () => { test.each([ [[1], [[0, 200], 404]], diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-array-strict.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-array-strict.yml new file mode 100644 index 0000000..a505eb5 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-array-strict.yml @@ -0,0 +1,22 @@ +- action: + name: post_fixture + data: + request: + path: /array-strict + method: POST + body: ["a", "b"] + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /array-strict + method: POST + bodyJSON: ["a", "b"] + expectation: + status: 200 diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-array.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-array.yml new file mode 100644 index 0000000..7481afa --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-array.yml @@ -0,0 +1,57 @@ +- action: + name: post_fixture + data: + request: + path: /empty-array + method: POST + body: [] + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /empty-array + method: POST + bodyJSON: [] + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /empty-array-empty-object + method: POST + body: [] + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /empty-array-empty-object + method: POST + bodyJSON: {} + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /array + method: POST + body: ["a", "b"] + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /array + method: POST + bodyJSON: ["a", "b"] + expectation: + status: 200 \ No newline at end of file diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-object-strict.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-object-strict.yml new file mode 100644 index 0000000..2284da9 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-object-strict.yml @@ -0,0 +1,86 @@ +- action: + name: post_fixture + data: + request: + path: /object-two-keys + method: POST + body: + a: a + b: b + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-two-keys + method: POST + bodyJSON: + a: a + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-null + method: POST + body: + a: null + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-null + method: POST + bodyJSON: + a: null + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-strict-deep + method: POST + body: + a: + aa: ['a', 'a'] + ab: [] + ac: 42 + b: + ba: ['b', 'a'] + c: c + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-strict-deep + method: POST + bodyJSON: + a: + aa: [ 'a', 'a' ] + ab: [] + ac: 42 + b: + ba: [ 'b', 'a' ] + c: c + expectation: + status: 200 \ No newline at end of file diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-object.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-object.yml new file mode 100644 index 0000000..37786d0 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-object.yml @@ -0,0 +1,185 @@ +- action: + name: post_fixture + data: + request: + path: /empty-object + method: POST + body: {} + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /empty-object + method: POST + body: {} + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /empty-object-empty-array + method: POST + body: {} + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /empty-object-empty-array + method: POST + bodyJSON: [] + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-one-key + method: POST + body: + a: a + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-one-key + method: POST + bodyJSON: + a: a + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-two-keys + method: POST + body: + a: a + b: b + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-two-keys + method: POST + bodyJSON: + a: a + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-null + method: POST + body: + a: null + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-null + method: POST + bodyJSON: + a: null + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-partial + method: POST + body: + a: a + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-partial + method: POST + bodyJSON: + a: a + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-partial-deep + method: POST + body: + a: + aa: aa + b: b + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-partial-deep + method: POST + bodyJSON: + a: + aa: aa + ax: ax + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /object-partial-deep-array + method: POST + body: + a: + aa: ['a', 'a'] + ab: [] + ac: 42 + b: + ba: ['b', 'a'] + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-partial-deep-array + method: POST + bodyJSON: + a: + aa: [ 'a', 'a' ] + ab: [] + ac: 42 + ax: ax + b: + ba: [ 'b', 'a' ] + bx: bx + c: c + expectation: + status: 200 \ No newline at end of file diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-regex.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-regex.yml new file mode 100644 index 0000000..46219fd --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-regex.yml @@ -0,0 +1,164 @@ +- action: + name: post_fixture + data: + request: + path: /regex-array + method: POST + body: + - a + - b + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-array + method: POST + bodyJSON: + - a + - b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /regex-object + method: POST + body: {} + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-object + method: POST + bodyJSON: + - a + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /regex-object + method: POST + body: + a: a + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-object + method: POST + bodyJSON: + a: a + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /regex-object-value + method: POST + body: + x: '/A+/ig' + options: + body: + allowRegex: true + response: + status: 200 + options: + lifetime: 2 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-object-value + method: POST + bodyJSON: + x: aAaA + expectation: + status: 200 +- action: + name: test_fixture + data: + path: /regex-object-value + method: POST + bodyJSON: + x: aAaA + b: b + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /regex-object-array + method: POST + body: + a: + b: b + c: [] + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-object-array + method: POST + bodyJSON: + a: + b: b + c: [] + expectation: + status: 200 +- action: + name: post_fixture + data: + request: + path: /regex-object-regex-array + method: POST + body: + x: '/A+/ig' + arr: [] + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /regex-object-regex-array + method: POST + bodyJSON: + x: aAaA + arr: [] + expectation: + status: 200 diff --git a/packages/test-cases/test-files/fixtures/matching/body/matching-body-string.yml b/packages/test-cases/test-files/fixtures/matching/body/matching-body-string.yml new file mode 100644 index 0000000..60d32b5 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/matching-body-string.yml @@ -0,0 +1,38 @@ +- action: + name: post_fixture + data: + request: + path: /empty-string + method: POST + body: "" + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /empty-string + method: POST + body: "" + expectation: + status: 200 +#- action: +# name: post_fixture +# data: +# request: +# path: /string +# method: POST +# body: a +# response: +# status: 200 +# expectation: +# status: 201 +#- action: +# name: test_fixture +# data: +# path: /string +# method: POST +# body: a +# expectation: +# status: 200 \ No newline at end of file diff --git a/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array-strict.yml b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array-strict.yml new file mode 100644 index 0000000..a505eb5 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array-strict.yml @@ -0,0 +1,22 @@ +- action: + name: post_fixture + data: + request: + path: /array-strict + method: POST + body: ["a", "b"] + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /array-strict + method: POST + bodyJSON: ["a", "b"] + expectation: + status: 200 diff --git a/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array.yml b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array.yml new file mode 100644 index 0000000..8e415e3 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-array.yml @@ -0,0 +1,19 @@ +- action: + name: post_fixture + data: + request: + path: /array + method: POST + body: ["a", "b"] + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /array + method: POST + bodyJSON: ["b", "a"] + expectation: + status: 404 \ No newline at end of file diff --git a/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object-strict.yml b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object-strict.yml new file mode 100644 index 0000000..9712a0e --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object-strict.yml @@ -0,0 +1,34 @@ +- action: + name: post_fixture + data: + request: + path: /object-strict-two-keys + method: POST + body: + a: a + b: b + options: + body: + strict: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-strict-two-keys + method: POST + bodyJSON: + a: a + expectation: + status: 404 +- action: + name: test_fixture + data: + path: /object-strict-two-keys + method: POST + bodyJSON: + b: b + expectation: + status: 404 diff --git a/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object.yml b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object.yml new file mode 100644 index 0000000..69038f5 --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-object.yml @@ -0,0 +1,45 @@ +- action: + name: post_fixture + data: + request: + path: /object + method: POST + body: + a: {} + b: b + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object + method: POST + bodyJSON: + b: b + expectation: + status: 404 +- action: + name: post_fixture + data: + request: + path: /object-type + method: POST + body: + a: [] + b: b + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /object-type + method: POST + bodyJSON: + a: {} + b: b + expectation: + status: 404 diff --git a/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-regex.yml b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-regex.yml new file mode 100644 index 0000000..1747e1f --- /dev/null +++ b/packages/test-cases/test-files/fixtures/matching/body/no-matching-body-regex.yml @@ -0,0 +1,22 @@ +- action: + name: post_fixture + data: + request: + path: /array + method: POST + body: ["a", "b"] + options: + body: + allowRegex: true + response: + status: 200 + expectation: + status: 201 +- action: + name: test_fixture + data: + path: /array + method: POST + bodyJSON: ["b", "a"] + expectation: + status: 404 \ No newline at end of file