@zimic/interceptor 1.0.2-canary.0 → 1.0.2-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/http.js +29 -29
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +29 -29
- package/dist/http.mjs.map +1 -1
- package/package.json +4 -4
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +32 -30
- package/src/http/requestHandler/types/restrictions.ts +1 -1
package/dist/http.mjs
CHANGED
|
@@ -703,11 +703,8 @@ var HttpRequestHandlerClient = class {
|
|
|
703
703
|
}
|
|
704
704
|
async matchesRequest(request) {
|
|
705
705
|
const hasDeclaredResponse = this.createResponseDeclaration !== void 0;
|
|
706
|
-
if (!hasDeclaredResponse) {
|
|
707
|
-
return false;
|
|
708
|
-
}
|
|
709
706
|
const restrictionsMatch = await this.matchesRequestRestrictions(request);
|
|
710
|
-
if (restrictionsMatch.
|
|
707
|
+
if (restrictionsMatch.success) {
|
|
711
708
|
this.numberOfMatchedRequests++;
|
|
712
709
|
} else {
|
|
713
710
|
const shouldSaveUnmatchedGroup = this.interceptor.requestSaving.enabled && this.restrictions.length > 0 && this.timesDeclarationPointer !== void 0;
|
|
@@ -715,8 +712,11 @@ var HttpRequestHandlerClient = class {
|
|
|
715
712
|
this.unmatchedRequestGroups.push({ request, diff: restrictionsMatch.diff });
|
|
716
713
|
}
|
|
717
714
|
}
|
|
715
|
+
if (!hasDeclaredResponse) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
718
|
const isWithinLimits = this.numberOfMatchedRequests <= this.limits.numberOfRequests.max;
|
|
719
|
-
return restrictionsMatch.
|
|
719
|
+
return restrictionsMatch.success && isWithinLimits;
|
|
720
720
|
}
|
|
721
721
|
async matchesRequestRestrictions(request) {
|
|
722
722
|
for (const restriction of this.restrictions) {
|
|
@@ -724,7 +724,7 @@ var HttpRequestHandlerClient = class {
|
|
|
724
724
|
const matchesComputedRestriction = await restriction(request);
|
|
725
725
|
if (!matchesComputedRestriction) {
|
|
726
726
|
return {
|
|
727
|
-
|
|
727
|
+
success: false,
|
|
728
728
|
diff: { computed: { expected: true, received: false } }
|
|
729
729
|
};
|
|
730
730
|
}
|
|
@@ -733,10 +733,10 @@ var HttpRequestHandlerClient = class {
|
|
|
733
733
|
const matchesHeadersRestrictions = this.matchesRequestHeadersRestrictions(request, restriction);
|
|
734
734
|
const matchesSearchParamsRestrictions = this.matchesRequestSearchParamsRestrictions(request, restriction);
|
|
735
735
|
const matchesBodyRestrictions = await this.matchesRequestBodyRestrictions(request, restriction);
|
|
736
|
-
const matchesRestriction = matchesHeadersRestrictions.
|
|
736
|
+
const matchesRestriction = matchesHeadersRestrictions.success && matchesSearchParamsRestrictions.success && matchesBodyRestrictions.success;
|
|
737
737
|
if (!matchesRestriction) {
|
|
738
738
|
return {
|
|
739
|
-
|
|
739
|
+
success: false,
|
|
740
740
|
diff: {
|
|
741
741
|
headers: matchesHeadersRestrictions.diff,
|
|
742
742
|
searchParams: matchesSearchParamsRestrictions.diff,
|
|
@@ -745,77 +745,77 @@ var HttpRequestHandlerClient = class {
|
|
|
745
745
|
};
|
|
746
746
|
}
|
|
747
747
|
}
|
|
748
|
-
return {
|
|
748
|
+
return { success: true };
|
|
749
749
|
}
|
|
750
750
|
matchesRequestHeadersRestrictions(request, restriction) {
|
|
751
751
|
if (restriction.headers === void 0) {
|
|
752
|
-
return {
|
|
752
|
+
return { success: true };
|
|
753
753
|
}
|
|
754
754
|
const restrictedHeaders = new HttpHeaders(
|
|
755
755
|
restriction.headers
|
|
756
756
|
);
|
|
757
757
|
const matchesRestriction = restriction.exact ? request.headers.equals(restrictedHeaders) : request.headers.contains(restrictedHeaders);
|
|
758
|
-
return matchesRestriction ? {
|
|
759
|
-
|
|
758
|
+
return matchesRestriction ? { success: true } : {
|
|
759
|
+
success: false,
|
|
760
760
|
diff: { expected: restrictedHeaders, received: request.headers }
|
|
761
761
|
};
|
|
762
762
|
}
|
|
763
763
|
matchesRequestSearchParamsRestrictions(request, restriction) {
|
|
764
764
|
if (restriction.searchParams === void 0) {
|
|
765
|
-
return {
|
|
765
|
+
return { success: true };
|
|
766
766
|
}
|
|
767
767
|
const restrictedSearchParams = new HttpSearchParams(
|
|
768
768
|
restriction.searchParams
|
|
769
769
|
);
|
|
770
770
|
const matchesRestriction = restriction.exact ? request.searchParams.equals(restrictedSearchParams) : request.searchParams.contains(restrictedSearchParams);
|
|
771
|
-
return matchesRestriction ? {
|
|
772
|
-
|
|
771
|
+
return matchesRestriction ? { success: true } : {
|
|
772
|
+
success: false,
|
|
773
773
|
diff: { expected: restrictedSearchParams, received: request.searchParams }
|
|
774
774
|
};
|
|
775
775
|
}
|
|
776
776
|
async matchesRequestBodyRestrictions(request, restriction) {
|
|
777
777
|
if (restriction.body === void 0) {
|
|
778
|
-
return {
|
|
778
|
+
return { success: true };
|
|
779
779
|
}
|
|
780
780
|
const body = request.body;
|
|
781
781
|
const restrictionBody = restriction.body;
|
|
782
782
|
if (typeof body === "string" && typeof restrictionBody === "string") {
|
|
783
783
|
const matchesRestriction2 = restriction.exact ? body === restrictionBody : body.includes(restrictionBody);
|
|
784
|
-
return matchesRestriction2 ? {
|
|
785
|
-
|
|
784
|
+
return matchesRestriction2 ? { success: true } : {
|
|
785
|
+
success: false,
|
|
786
786
|
diff: { expected: restrictionBody, received: body }
|
|
787
787
|
};
|
|
788
788
|
}
|
|
789
789
|
if (restrictionBody instanceof HttpFormData) {
|
|
790
790
|
if (!(body instanceof HttpFormData)) {
|
|
791
791
|
return {
|
|
792
|
-
|
|
792
|
+
success: false,
|
|
793
793
|
diff: { expected: restrictionBody, received: body }
|
|
794
794
|
};
|
|
795
795
|
}
|
|
796
796
|
const matchesRestriction2 = restriction.exact ? await body.equals(restrictionBody) : await body.contains(restrictionBody);
|
|
797
|
-
return matchesRestriction2 ? {
|
|
798
|
-
|
|
797
|
+
return matchesRestriction2 ? { success: true } : {
|
|
798
|
+
success: false,
|
|
799
799
|
diff: { expected: restrictionBody, received: body }
|
|
800
800
|
};
|
|
801
801
|
}
|
|
802
802
|
if (restrictionBody instanceof HttpSearchParams) {
|
|
803
803
|
if (!(body instanceof HttpSearchParams)) {
|
|
804
804
|
return {
|
|
805
|
-
|
|
805
|
+
success: false,
|
|
806
806
|
diff: { expected: restrictionBody, received: body }
|
|
807
807
|
};
|
|
808
808
|
}
|
|
809
809
|
const matchesRestriction2 = restriction.exact ? body.equals(restrictionBody) : body.contains(restrictionBody);
|
|
810
|
-
return matchesRestriction2 ? {
|
|
811
|
-
|
|
810
|
+
return matchesRestriction2 ? { success: true } : {
|
|
811
|
+
success: false,
|
|
812
812
|
diff: { expected: restrictionBody, received: body }
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
815
|
if (restrictionBody instanceof Blob || restrictionBody instanceof ArrayBuffer || restrictionBody instanceof ReadableStream) {
|
|
816
816
|
if (!(body instanceof Blob)) {
|
|
817
817
|
return {
|
|
818
|
-
|
|
818
|
+
success: false,
|
|
819
819
|
diff: { expected: restrictionBody, received: body }
|
|
820
820
|
};
|
|
821
821
|
}
|
|
@@ -831,14 +831,14 @@ var HttpRequestHandlerClient = class {
|
|
|
831
831
|
restrictionBodyAsBlob = restrictionBody;
|
|
832
832
|
}
|
|
833
833
|
const matchesRestriction2 = await blobEquals_default(body, restrictionBodyAsBlob);
|
|
834
|
-
return matchesRestriction2 ? {
|
|
835
|
-
|
|
834
|
+
return matchesRestriction2 ? { success: true } : {
|
|
835
|
+
success: false,
|
|
836
836
|
diff: { expected: restrictionBody, received: body }
|
|
837
837
|
};
|
|
838
838
|
}
|
|
839
839
|
const matchesRestriction = restriction.exact ? jsonEquals_default(request.body, restriction.body) : jsonContains_default(request.body, restriction.body);
|
|
840
|
-
return matchesRestriction ? {
|
|
841
|
-
|
|
840
|
+
return matchesRestriction ? { success: true } : {
|
|
841
|
+
success: false,
|
|
842
842
|
diff: { expected: restrictionBody, received: body }
|
|
843
843
|
};
|
|
844
844
|
}
|