|
1 | | -import { describe, expect, it } from 'vitest'; |
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
2 | 2 |
|
3 | 3 | import type { BaseUrl, GraphQLRequestArtifact } from '@/utils/types'; |
4 | 4 |
|
@@ -38,13 +38,15 @@ describe('matchGraphQLRequestArtifacts', () => { |
38 | 38 | expect(matched).toHaveLength(0); |
39 | 39 | }); |
40 | 40 |
|
41 | | - it('Should match query string ignoring whitespace', () => { |
| 41 | + it('Should match equivalent queries with different insignificant whitespace', () => { |
42 | 42 | const matched = matchGraphQLRequestArtifacts({ |
43 | 43 | artifacts: [makeArtifact({ query: 'query { User { name } }' })], |
44 | 44 | meta: { |
45 | 45 | path: '/', |
46 | 46 | operationType: 'query', |
47 | | - query: 'query { User { name } }' |
| 47 | + query: `query { |
| 48 | + User { name } |
| 49 | + }` |
48 | 50 | } |
49 | 51 | }); |
50 | 52 | expect(matched).toHaveLength(1); |
@@ -123,6 +125,39 @@ describe('matchGraphQLRequestArtifacts', () => { |
123 | 125 | expect(matched).toHaveLength(1); |
124 | 126 | }); |
125 | 127 |
|
| 128 | + it('Should match operation name regexp with case-insensitive flag', () => { |
| 129 | + const matched = matchGraphQLRequestArtifacts({ |
| 130 | + artifacts: [makeArtifact({ operationName: /^getusers$/i })], |
| 131 | + meta: { |
| 132 | + path: '/', |
| 133 | + operationType: 'query', |
| 134 | + operationName: 'GetUsers' |
| 135 | + } |
| 136 | + }); |
| 137 | + expect(matched).toHaveLength(1); |
| 138 | + }); |
| 139 | + |
| 140 | + it('Should skip artifact with neither query nor operationName', () => { |
| 141 | + const warn = vi.spyOn(console, 'warn'); |
| 142 | + const artifact = makeArtifact({}); |
| 143 | + |
| 144 | + const matched = matchGraphQLRequestArtifacts({ |
| 145 | + artifacts: [artifact], |
| 146 | + meta: { |
| 147 | + path: '/', |
| 148 | + operationType: 'query', |
| 149 | + operationName: 'GetUsers' |
| 150 | + } |
| 151 | + }); |
| 152 | + |
| 153 | + expect(matched).toHaveLength(0); |
| 154 | + expect(warn).toHaveBeenCalledWith( |
| 155 | + `[mock-config] GraphQL artifact with no query or operationName was skipped: ${JSON.stringify( |
| 156 | + artifact |
| 157 | + )}` |
| 158 | + ); |
| 159 | + }); |
| 160 | + |
126 | 161 | it('Should fail operation name regexp when pattern does not match', () => { |
127 | 162 | const matched = matchGraphQLRequestArtifacts({ |
128 | 163 | artifacts: [makeArtifact({ operationName: /^Other$/ })], |
|
0 commit comments