Loading
fix(httpctrl): match POST query stubs on the selector without crashing
A stub for POST /ngsi-ld/v1/entityOperations/query matches only when the first entity selector in the request has the same type and id as the stub's response body. This check had four problems: - An array response body (what a query returns) caused a TypeError, and the mock sent no answer. D011_02_red_02, D011_03_inc_02 and D011_04_inc_02 use such stubs. - The type was compared as plain text. A broker that sends the full type IRI (https://ngsi-ld-test-suite/context#Vehicle) never matched a body with type Vehicle. D010_03_inc_03 fails this way. - A selector with only an id, only a type, or no entities caused a KeyError. - Get Stub Count sends no request body, so counting such a stub caused an AttributeError. Move the check into one function and use it in both places. A stub matches when one entity in its response body (object or array) fits the type and/or id of the selector. The id may be a list. The type also matches by its last part after '#' or '/', because the mock does not read @context. Without a request body (Get Stub Count), the stub matches by method and URL, like any other stub.