Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support input&output in the intercept API. #1

Open
dohooo opened this issue Nov 19, 2024 · 0 comments
Open

Support input&output in the intercept API. #1

dohooo opened this issue Nov 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@dohooo
Copy link

dohooo commented Nov 19, 2024

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;
		});
	});
@dohooo dohooo added the enhancement New feature or request label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants