Anthony Bennett
12/27/2022, 8:20 PMTimothy Jones
12/28/2022, 11:23 AMTimothy Jones
12/28/2022, 11:24 AMTimothy Jones
12/28/2022, 11:25 AMjest.config.js is “chore: Collect test coverage”, so I guess it doesn’t.
Anyway, you set collectCoverage: true,Timothy Jones
12/28/2022, 11:26 AM--coverageTimothy Jones
12/28/2022, 11:26 AMAnthony Bennett
12/28/2022, 2:07 PMTimothy Jones
12/28/2022, 4:09 PMTimothy Jones
12/28/2022, 4:09 PMTimothy Jones
12/28/2022, 4:10 PMTimothy Jones
12/28/2022, 4:11 PMAnthony Bennett
12/28/2022, 4:22 PMWhile the coverage metric can be helpful, it unfortunately won't be able to tell you whether or not you've covered every semantic variation of an endpoint. Determining that is currently beyond the scope of Pact, but is something that we would love to be able to solve in the future.Timothy Jones
12/28/2022, 7:17 PMTimothy Jones
12/28/2022, 7:17 PMTimothy Jones
12/28/2022, 8:33 PM{
getAllProducts: () => server.authedGet<string[]>('/products'),
getProduct: (id) => server.authedGet(`/products/${id}`),
health: () =>
server.get<WireServerHealth>('/health').then(({ status }) => status),
};Timothy Jones
12/28/2022, 8:34 PMTimothy Jones
12/28/2022, 8:35 PMauthedGet: (path) =>
axios
.get(`${baseurl}${path}`, {
headers: { Authorization: `Bearer ${authToken}` },
})
.then(unmarshallSuccess, unmarshallFailure),
get: (path) =>
axios
.get(`${baseurl}${path}`, {})
.then(unmarshallSuccess, unmarshallFailure),Timothy Jones
12/28/2022, 8:35 PMexport const unmarshallSuccess = <T>(response: AxiosResponse<T>): T =>
response.data;Timothy Jones
12/28/2022, 8:35 PMconst isWireErrorResponse = (data: unknown): data is WireErrorResponse => {
const maybeResponse = data as WireErrorResponse;
return 'message' in maybeResponse && typeof maybeResponse === 'string';
};
export const unmarshallFailure = (error: Error): never => {
if (axios.isAxiosError(error)) {
if (error.response) {
if (error.response.status === 401) {
throw new ApiError(
"The server says that you're not authorised.",
API_NOT_AUTHORISED
);
}
throw new ApiError(
error.response.data && isWireErrorResponse(error.response.data)
? error.response.data.message
: `The server returned an error code (${error.response.status})`,
API_ERROR
);
}
if (error.request) {
throw new ApiError("The server didn't respond", API_NO_RESPONSE);
}
}
throw new Error(`[API Failed] ${error.message}`);
};Timothy Jones
12/28/2022, 8:36 PMTimothy Jones
12/28/2022, 8:36 PMTimothy Jones
12/28/2022, 8:38 PMTimothy Jones
12/28/2022, 8:41 PMTimothy Jones
12/28/2022, 8:47 PMgetProduct(id: string): () => server.authedGet<Product>(`/products/${id}`)
.then(unmarshallSuccess, unmarshallFailure),
were hit, we don’t know if this tests all types of product that we might get.Timothy Jones
12/28/2022, 8:48 PMif (error.request) {
throw new ApiError("The server didn't respond", API_NO_RESPONSE);
}Timothy Jones
12/28/2022, 9:01 PMTimothy Jones
12/28/2022, 9:02 PMTimothy Jones
12/29/2022, 3:07 AMAnthony Bennett
12/29/2022, 12:56 PMAnthony Bennett
12/29/2022, 1:01 PMTimothy Jones
12/30/2022, 2:11 PM