Skip to content

Support input&output in the intercept API. #1

@dohooo

Description

@dohooo

Per title

			if (lastArg === 'intercept') {
				return cy
					.intercept(`/api/trpc/${path}*`, (req) => {
						// Extract and deserialize input from request
						const input = req.body?.json && transformer.input.deserialize(req.body.json)?.json;

						req.continue((res) => {
							if (typedOpts[0]) {
								const output =
									res?.body?.result?.data &&
									transformer.output.deserialize(res.body.result.data)?.json;

								// Pass both input and output to the transform callback
								const transformedOutput = typedOpts[0]({
									input,
									output,
								});

								res.body.result.data = {
									json: transformer.output.serialize(transformedOutput),
								};
							}
						});
					})
					.as(path);
			}
	it('should show threads list with the correct count', () => {
		cy.api.thread.list.intercept(({ output, input }) => {
			const pageSize = input?.limit || 20;
			const totalThreadsCount = output.pageInfo.total_count;

			cy.get('[data-testid=thread-list-container]')
				.find(`[data-testid^="thread-item-"]`)
				.should('have.length', Math.min(pageSize, totalThreadsCount));

			return output;
		});
	});

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions