Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Merge branch 'master' into feat/logs-custom-sql-querying

TzeYiingeddb074e9cc4
diff --cc studio/tests/pages/projects/logs.test.js
index bd26f4c8c72,bb9107a467e..aa50c0d2555
--- a/studio/tests/pages/projects/logs.test.js
+++ b/studio/tests/pages/projects/logs.test.js
@@@ -178,54 -202,42 +202,94 @@@ test('where clause will trigger a log r
await waitFor(() => screen.getByText(/happened/))
})
+test('custom sql querying', async () => {
+ get.mockImplementation((url) => {
+ if (url.includes('sql=') && url.includes('select')) {
+ return {
+ data: [
+ {
+ my_count: 12345,
+ },
+ ],
+ }
+ }
+ return { data: [] }
+ })
+ const { container } = render(<LogPage />)
+ let editor = container.querySelector('.monaco-editor')
+ expect(editor).toBeFalsy()
+ // TODO: abstract this out into a toggle selection helper
+ const toggle = getToggleByText(/via query/)
+ expect(toggle).toBeTruthy()
+ userEvent.click(toggle)
+
+ // type into the query editor
+ await waitFor(() => {
+ editor = container.querySelector('.monaco-editor')
+ expect(editor).toBeTruthy()
+ })
+ editor = container.querySelector('.monaco-editor')
+ userEvent.type(editor, 'select count(*) as my_count from edge_logs')
+
+ // should show sandbox warning alert
+ await waitFor(() => screen.getByText(/free users are restricted to a 7 day querying window/))
+
+ // should trigger query
+ userEvent.click(screen.getByText('Run'))
+ await waitFor(
+ () => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('sql='))
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('select'))
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('edge_logs'))
+ expect(get).not.toHaveBeenCalledWith(expect.stringContaining('where'))
+ },
+ { timeout: 1000 }
+ )
+
+ await waitFor(() => screen.getByText(/my_count/)) //column header
+ await waitFor(() => screen.getByText(/12345/)) // row value
+
+ // clicking on the row value should not show log selection panel
+ userEvent.click(screen.getByText(/12345/))
+ await waitFor(() => expect(() => screen.getByText(/Metadata/)).toThrow())
+})
++
+ test('load older btn will fetch older logs', async () => {
+ get.mockImplementation((url) => {
+ if (url.includes('count')) {
+ return {}
+ }
+ return {
+ data: [
+ {
+ id: 'some-uuid',
+ timestamp: 1621323232312,
+ event_message: 'first event',
+ metadata: {},
+ },
+ ],
+ }
+ })
+ render(<LogPage />)
+ // should display first log but not second
+ await waitFor(() => screen.getByText('first event'))
+ expect(() => screen.getByText('second event')).toThrow()
+
+ get.mockResolvedValueOnce({
+ data: [
+ {
+ id: 'some-uuid2',
+ timestamp: 1621323232310,
+ event_message: 'second event',
+ metadata: {},
+ },
+ ],
+ })
+ // should display first and second log
+ userEvent.click(screen.getByText('Load older'))
+ await waitFor(() => screen.getByText('first event'))
+ await waitFor(() => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('timestamp_end=1'))
+ })
+ await waitFor(() => screen.getByText('second event'))
+ })