-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: mock resources #6760
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
Merged
Merged
feat: mock resources #6760
Changes from all commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
b7a2432
project ui changes
jackkav 6453541
project ui changes
jackkav 1bd5123
create mock server model
jackkav d9a03e8
model mock server similarly to design doc
jackkav 7aa5ebf
use spec modelling and nav
jackkav 7169ba5
layout pass
jackkav 9f178fc
rename requestbin to mock-route
jackkav a01211b
sidebar ui pass
jackkav 1999ebb
load mock server
jackkav a1acfd4
add url bar
jackkav ba740ff
can navigate to headers
jackkav af03b78
Refactor mock server and mock route creation and
jackkav 56ec7b2
route crud
jackkav 13b140b
sidebar layout
jackkav 704cf24
add delete guuard
jackkav ba3b639
patch route
jackkav d1173be
Add mock response tab to request pane
jackkav 31c154a
wire up mock servers in requests
jackkav a241d43
Update mock server and route selection in
jackkav 80408de
make it work without internet
jackkav ed2a19a
can create bin
jackkav b5efd5f
pass body and headers to bin
jackkav 7c67359
can fetch logs but cant see em
jackkav 3130126
split out response pane for hmr
jackkav fc86a7f
basic table
jackkav cb898dc
extract mock url bar
jackkav 168a974
add header tab
jackkav 45ab325
made a dumb cache
jackkav b04dd35
url bar pass
jackkav bfe7a77
send request and create response
jackkav 1fc07d0
wire up timeline
jackkav 555a3db
wire up preview
jackkav fbcdaa1
timeline useeffect
jackkav b7907ab
move to action
jackkav 9e8dea1
fix types
jackkav f419aa9
empty states
jackkav 1fabf30
rebase updating aria
jackkav 6422cfd
use har type
jackkav f7f2a8b
can edit bins
jackkav 6fe6e54
cookie support
jackkav 6eddbbd
wire up status
jackkav 207ac57
status text
jackkav 909f18d
magic status text
jackkav 988ccbe
ui
jackkav ad9de27
always use put rather than create bin
jackkav b0d71ae
add url to mock route
jackkav 3421412
scroll bar
jackkav 99dff32
add content types
jackkav 8da63a2
validation
jackkav 87a3781
fix flake
jackkav d411654
improve logs
jackkav d52ecf8
fix outlet warning
jackkav 9019178
fix send to mock endpoint
jackkav ff5db47
switch table to grid
gatzjames f5eeb41
handle errors
jackkav 35d0740
rotate log
jackkav 056a798
create mockbin on open if needed
jackkav 46a64d1
add full url ux
jackkav 24e0a4f
reverse log order
jackkav 15cb5b3
binId from store
jackkav d02ec06
remove http method
jackkav 69b653f
rename prefix
jackkav 7321005
use server Id for bin id
jackkav f8a9d0c
fix copy
jackkav bea6cf2
show log har
jackkav d578b37
fix url bar
jackkav c5d6cf7
fix button padding
jackkav 8f7d0ec
tailwind
jackkav be58f48
method select
jackkav 2fc0209
remove default status text
jackkav 4b0f724
full tailwind
jackkav da31803
fix breadcrumb
jackkav 3b011d0
default to json
jackkav ab99b7c
move copy to end, remove save
jackkav e1de9b6
error msg
jackkav 6cc3e15
only patch when needed
jackkav 298a8e1
fix ws colors
jackkav 3778616
fix command palette
jackkav 678cd17
add isMock helper
jackkav 28c7a6c
revert local storage mechanism
jackkav 86b7012
fix redirect
jackkav e86e797
fix ignore upsert
jackkav 28b2204
extract to constant
jackkav b479d3e
ui test
jackkav c9314cf
hide actions from mock-server
jackkav abc53c5
fix code editor onBlur
jackkav 30c2e1d
lift update to route
jackkav 5bd44c2
refactor to return only errors
jackkav a3de6c3
add url to mock server model
jackkav 41d77e9
select mock ui pass
jackkav bdc46d2
can modify url in settings
jackkav a29b30e
use server url from db if selected
jackkav c5f0bc3
hide url option
jackkav c4e451c
fix lint error
jackkav 75ee891
extract to file
jackkav 6d19575
remove binResponse
jackkav 4f036a4
can sync
jackkav be8c251
move things around
jackkav e0bc558
rename name path sync
jackkav e10b687
fix type check
jackkav cc76848
capture kvp onBlur
jackkav f714a18
fix error message
jackkav 8e06b94
basic mock test
jackkav 759087e
wire up mock patcher and navigate
jackkav bc6c96a
rename component
jackkav 35c5a48
remove url prop of route
jackkav 56ffa68
fix lint
jackkav f71b90b
fix test
jackkav 37e2a8f
temporary skip e2e test
jackkav fad32de
fix constant url
jackkav b0ae1f2
fix migration
jackkav c6403d3
remove console logs
jackkav 33b221d
rename function
jackkav 10f17e7
only create a single hidden request
jackkav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { test } from '../../playwright/test'; | ||
|
|
||
| // TODO: unskip this test when cloud mock is online | ||
| test.skip('can make a mock route', async ({ page }) => { | ||
| test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms'); | ||
| await page.getByLabel('New Mock Server').click(); | ||
| await page.getByRole('button', { name: 'Create', exact: true }).click(); | ||
| await page.getByRole('button', { name: 'New Mock Route' }).click(); | ||
| await page.getByText('GET/').click(); | ||
| await page.getByTestId('CodeEditor').getByRole('textbox').fill('123'); | ||
| await page.getByRole('tab', { name: 'Response Headers' }).click(); | ||
| await page.locator('.CodeMirror').first().click(); | ||
| await page.getByRole('textbox').nth(1).fill('my-header'); | ||
| await page.getByRole('textbox').nth(2).fill('my-value'); | ||
| await page.getByRole('tab', { name: 'Response Status' }).click(); | ||
| await page.getByPlaceholder('200').click(); | ||
| await page.getByPlaceholder('200').fill('201'); | ||
|
|
||
| await page.getByRole('button', { name: 'Test' }).click(); | ||
| await page.getByRole('tab', { name: 'Preview' }).click(); | ||
| await page.getByLabel('Preview').getByText('123').click(); | ||
| await page.getByRole('tab', { name: 'Timeline' }).click(); | ||
| await page.getByText('HTTP/1.1 201 Created').click(); | ||
| await page.getByText('my-header:').click(); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { isDesign, Workspace } from '../models/workspace'; | ||
| import { isDesign, isMockServer, Workspace } from '../models/workspace'; | ||
| import { strings } from './strings'; | ||
|
|
||
| export const getWorkspaceLabel = (workspace: Workspace) => | ||
| isDesign(workspace) ? strings.document : strings.collection; | ||
| isDesign(workspace) | ||
| ? strings.document | ||
| : isMockServer(workspace) | ||
| ? strings.mock | ||
| : strings.collection; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { database as db } from '../common/database'; | ||
| import type { BaseModel } from './index'; | ||
| import { RequestHeader } from './request'; | ||
|
|
||
| export const name = 'Mock Route'; | ||
|
|
||
| export const type = 'MockRoute'; | ||
|
|
||
| export const prefix = 'mock_route'; | ||
|
|
||
| export const canDuplicate = true; | ||
|
|
||
| export const canSync = true; | ||
|
|
||
| interface BaseMockRoute { | ||
| body: string; | ||
| headers: RequestHeader[]; | ||
| parentId: string; | ||
| statusCode: number; | ||
| statusText: string; | ||
| name: string; | ||
| mimeType: string;// response body type | ||
| method: string; // used only for sending the testing request | ||
| } | ||
|
|
||
| export type MockRoute = BaseModel & BaseMockRoute; | ||
|
|
||
| export function init(): BaseMockRoute { | ||
| return { | ||
| body: '', | ||
| headers: [], | ||
| parentId: '', | ||
| statusCode: 200, | ||
| statusText: '', | ||
| name: '/', | ||
| mimeType: 'application/json', | ||
| method: 'GET', | ||
| }; | ||
| } | ||
|
|
||
| export const isMockRoute = (model: Pick<BaseModel, 'type'>): model is MockRoute => ( | ||
| model.type === type | ||
| ); | ||
|
|
||
| export function migrate(doc: MockRoute) { | ||
| return doc; | ||
| } | ||
|
|
||
| export function create(patch: Partial<MockRoute> = {}) { | ||
| if (!patch.parentId) { | ||
| throw new Error('New MockRoute missing `parentId`: ' + JSON.stringify(patch)); | ||
| } | ||
|
|
||
| return db.docCreate<MockRoute>(type, patch); | ||
| } | ||
|
|
||
| export function update( | ||
| mockRoute: MockRoute, | ||
| patch: Partial<MockRoute> = {}, | ||
| ) { | ||
| return db.docUpdate<MockRoute>(mockRoute, patch); | ||
| } | ||
|
|
||
| export function getById(id: string) { | ||
| return db.get<MockRoute>(type, id); | ||
| } | ||
|
|
||
| export function findByParentId(parentId: string) { | ||
| return db.find<MockRoute>(type, { parentId }); | ||
| } | ||
|
|
||
| export function removeWhere(parentId: string) { | ||
| return db.removeWhere(type, { parentId }); | ||
| } | ||
|
|
||
| export function remove(mockRoute: MockRoute) { | ||
| return db.remove(mockRoute); | ||
| } | ||
|
|
||
| export function all() { | ||
| return db.all<MockRoute>(type); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { database as db } from '../common/database'; | ||
| import { type BaseModel, workspace } from './index'; | ||
|
|
||
| export const name = 'Mock Server'; | ||
|
|
||
| export const type = 'MockServer'; | ||
|
|
||
| export const prefix = 'mock'; | ||
|
|
||
| export const canDuplicate = true; | ||
|
|
||
| export const canSync = true; | ||
|
|
||
| interface BaseMockServer { | ||
| parentId: string; | ||
| name: string; | ||
| url: string; | ||
| useInsomniaCloud: boolean; | ||
| } | ||
|
|
||
| export type MockServer = BaseModel & BaseMockServer; | ||
|
|
||
| export function init(): BaseMockServer { | ||
| return { | ||
| parentId: '', | ||
| name: 'New Mock', | ||
| url: 'http://localhost:8080', | ||
| useInsomniaCloud: true, | ||
| }; | ||
| } | ||
|
|
||
| export const isMockServer = (model: Pick<BaseModel, 'type'>): model is MockServer => ( | ||
| model.type === type | ||
| ); | ||
|
|
||
| export function migrate(doc: MockServer) { | ||
| return doc; | ||
| } | ||
|
|
||
| export function create(patch: Partial<MockServer> = {}) { | ||
| if (!patch.parentId) { | ||
| throw new Error('New MockServer missing `parentId`: ' + JSON.stringify(patch)); | ||
| } | ||
|
|
||
| return db.docCreate<MockServer>(type, patch); | ||
| } | ||
| export async function getOrCreateForParentId( | ||
| workspaceId: string, | ||
| patch: Partial<MockServer> = {}, | ||
| ) { | ||
| const mockServer = await db.getWhere<MockServer>(type, { | ||
| parentId: workspaceId, | ||
| }); | ||
|
|
||
| if (!mockServer) { | ||
| return db.docCreate<MockServer>(type, { ...patch, parentId: workspaceId }); | ||
| } | ||
|
|
||
| return mockServer; | ||
| } | ||
| export function update( | ||
| mockServer: MockServer, | ||
| patch: Partial<MockServer> = {}, | ||
| ) { | ||
| return db.docUpdate<MockServer>(mockServer, patch); | ||
| } | ||
|
|
||
| export function getById(id: string) { | ||
| return db.get<MockServer>(type, id); | ||
| } | ||
|
|
||
| export function getByParentId(parentId: string) { | ||
| return db.getWhere<MockServer>(type, { parentId }); | ||
| } | ||
|
|
||
| export async function findByProjectId(projectId: string) { | ||
| const workspaces = await workspace.findByParentId(projectId); | ||
| return db.find<MockServer>(type, { parentId: { $in: workspaces.map(ws => ws._id) } }); | ||
| } | ||
|
|
||
| export function removeWhere(parentId: string) { | ||
| return db.removeWhere(type, { parentId }); | ||
| } | ||
|
|
||
| export function remove(mockServer: MockServer) { | ||
| return db.remove(mockServer); | ||
| } | ||
|
|
||
| export function all() { | ||
| return db.all<MockServer>(type); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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