Skip to content

feat: mock resources#6760

Merged
jackkav merged 114 commits intoKong:developfrom
jackkav:feat/mock-servers
Jan 24, 2024
Merged

feat: mock resources#6760
jackkav merged 114 commits intoKong:developfrom
jackkav:feat/mock-servers

Conversation

@jackkav
Copy link
Contributor

@jackkav jackkav commented Nov 6, 2023

goal:

Support API mocking features.

terminology:

  • "mock server" a group of "mock routes", perhaps with a remotely assigned url the user can copy and use in their app, TBD as server provisioning is an external concern, perhaps mock resource
  • "mock route" a stubbed response, perhaps with remote url, route to resolve, TBD as route clashes with react route
  • "example response" a saved template used to populate a request bin, saved from a custom form or generated from an OAS spec or existing response

ideas for next pass:

  • could transform a request collection into a mock server/mock routes
  • could transform a design document into a mock server/mock routes
  • could add a mock server navigation to design document menu pills and add pills to collection
  • could use kong dialect to describe services and routes if we can find a payoff in orchestration or extension
  • should derived mock servers be editable?
  • could use the same relationships as a spec, however scope will be migrated if old version is used

questions

  • data model
    • to use mock route path and name or just name?
      • additive, it should be cheap to add. apth field later if we need to use name for something else
    • to record url in the route or make it a product of server
      • remove url from route
    • to write response body to file in order to model responses more closely
      • could create body size and content type validator to ensure responses are always human readable content
  • should be a child of project or workspace?
  • request bins cannot be edited, should we reuse or rebuild?
  • should mock servers interact with environments?
  • abstractions
    • requestheaderseditor
  • alternate protocols? besides http, sse, gql, grpc, websockets?

todo:

  • project pane UI
  • wire up mock server crud actions
  • wire up mock route crud actions
  • sidebar
  • url bar
  • response editor
  • mock response UI inside collection
  • send to mock url feature, insomnia network stack side, show response, from request tab and from mock server editor
  • request bin/mock server activity fetched from mockbin api
  • send to mock url, server POC side
  • path and naming?
  • fix command palette
  • remove offline mode workaround
  • fix button sizing of collection settings
  • icon bg color
  • in order not to break downgraded mock servers we will need to make a new workspace key to replace scope, because scope is forced to defualt to design when unknown prior to adding mock server.
  • fix duplicate
  • rename mock server to mock
  • fix mock settings
  • persist mock route onblur in tabs
  • default cloud mock server, radio button local mock server and input, use create project dialog style
  • check route modal for unused fields
  • sync
  • onblur update mockbin on header key or value blur if key has value
  • smoke test
    • github action containerised services for redis and mockbin
    • use our infra
    • build fs adapter and run mockbin in the action with node
  • move mock response tab into response pane
  • maybe move url out of mock route and make it just a product of server id and env var
  • maybe write response body to file
  • create only one hidden request under mock route

future work

  • spike transform OAS response objects to mock server
  • aggregate logs per server somehow
  • sync with mockbin at route patch time rather than seperately, handle errors differently
  • sync story and nesting mocks inside desing/debug/test/mock thing
  • extract the path from a url when extracting a mock from a response
  • extract multiple mocks from collection/folder by paths and responses
  • extract from HARs
  • folders and drag and drop, ordering
  • restrict mock body size in order to avoid breaking the database
  • improve extract mock ux,
    • sync with mockbin after extraction
    • infer path from request url
    • block oversized and invalid content type
  • use insomniaFetch with url override?
  • auto add content type header?

design:

image
  • should history be the default pane?
  • mockbin api cannot specify a method, still show it for test button?
  • does environment make sense to use for this?
  • does cookie modal make sense here?

missteps

  • made a new mock server object and try to show it on the project view, too difficult to play nice with the workspaceWithMetadata concept, easier to match design spec -> workspace relationship

Notes

attempting to wire up without pathing server to get a working pass before adding a dependency on a backend store for resolving routes to bins.
this begs a few questions; what if the backend is inconsistent with the ui what the user experience should be? what if the backend is inconsistent with the mockbin state.

Ideally all we will have access to the mockbin state store to avoid inconsistencies.

closes INS-3246

@jackkav jackkav self-assigned this Nov 6, 2023
@CLAassistant
Copy link

CLAassistant commented Nov 20, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jackkav jackkav changed the title mock servers feat: mock resources Nov 22, 2023
@jackkav
Copy link
Contributor Author

jackkav commented Nov 24, 2023

image

@jackkav jackkav force-pushed the feat/mock-servers branch 2 times, most recently from 5d96e37 to cdf99ac Compare November 24, 2023 02:45
@jackkav jackkav force-pushed the feat/mock-servers branch 3 times, most recently from 299b3d0 to 5e7e885 Compare December 18, 2023 08:46
@jackkav jackkav force-pushed the feat/mock-servers branch 3 times, most recently from f644d2b to 43cc85f Compare December 21, 2023 12:05
@jackkav jackkav force-pushed the feat/mock-servers branch 2 times, most recently from 4ddeb9f to a09f191 Compare January 10, 2024 11:39
@jackkav jackkav force-pushed the feat/mock-servers branch 4 times, most recently from 51f29c6 to bc70627 Compare January 22, 2024 14:52
@jackkav jackkav marked this pull request as ready for review January 23, 2024 09:25
filfreire
filfreire previously approved these changes Jan 23, 2024
Copy link
Contributor

@filfreire filfreire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️🏎️

gatzjames
gatzjames previously approved these changes Jan 24, 2024
import { test } from '../../playwright/test';

// TODO: unskip this test when cloud mock is online
test.skip('can make a mock route', async ({ page }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to change this when the api is deployed

<Heading>Actions</Heading>
<PromptButton
onClick={async () => {
const docs = await db.withDescendants(workspace, models.request.type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todo: For next pass move this to database methods and perhaps put it on an action

@jackkav jackkav dismissed stale reviews from gatzjames and filfreire via c6403d3 January 24, 2024 12:58
@jackkav jackkav enabled auto-merge (squash) January 24, 2024 14:10
@jackkav jackkav disabled auto-merge January 24, 2024 15:38
@jackkav jackkav merged commit 557e5c0 into Kong:develop Jan 24, 2024
@jackkav jackkav deleted the feat/mock-servers branch January 24, 2024 15:38
jackkav added a commit to jackkav/insomnia that referenced this pull request Mar 13, 2024
* project ui changes

* project ui changes

* create mock server model

* model mock server similarly to design doc

* use spec modelling and nav

* layout pass

* rename requestbin to mock-route

* sidebar ui pass

* load mock server

* add url bar

* can navigate to headers

* Refactor mock server and mock route creation and
retrieval

* route crud

* sidebar layout

* add delete guuard

* patch route

* Add mock response tab to request pane

* wire up mock servers in requests

* Update mock server and route selection in
RequestPane

* make it work without internet

* can create bin

* pass body and headers to bin

* can fetch logs but cant see em

* split out response pane for hmr

* basic table

* extract mock url bar

* add header tab

* made a dumb cache

* url bar pass

* send request and create response

* wire up timeline

* wire up preview

* timeline useeffect

* move to action

* fix types

* empty states

* rebase updating aria

* use har type

* can edit bins

* cookie support

* wire up status

* status text

* magic status text

* ui

* always use put rather than create bin

* add url to mock route

* scroll bar

* add content types

* validation

* fix flake

* improve logs

* fix outlet warning

* fix send to mock endpoint

* switch table to grid

* handle errors

* rotate log

* create mockbin on open if needed

* add full url ux

* reverse log order

* binId from store

* remove http method

* rename prefix

* use server Id for bin id

* fix copy

* show log har

* fix url bar

* fix button padding

* tailwind

* method select

* remove default status text

* full tailwind

* fix breadcrumb

* default to json

* move copy to end, remove save

* error msg

* only patch when needed

* fix ws colors

* fix command palette

* add isMock helper

* revert local storage mechanism

* fix redirect

* fix ignore upsert

* extract to constant

* ui test

* hide actions from mock-server

* fix code editor onBlur

* lift update to route

* refactor to return only errors

* add url to mock server model

* select mock ui pass

* can modify url in settings

* use server url from db if selected

* hide url option

* fix lint error

* extract to file

* remove binResponse

* can sync

* move things around

* rename name path sync

* fix type check

* capture kvp onBlur

* fix error message

* basic mock test

* wire up mock patcher and navigate

* rename component

* remove url prop of route

* fix lint

* fix test

* temporary skip e2e test

* fix constant url

* fix migration

* remove console logs

* rename function

* only create a single hidden request

---------

Co-authored-by: gatzjames <jamesgatzos@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants