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

Realtime provider #1288

Merged
merged 99 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5737f5d
add dummy structure
umutzd Nov 15, 2021
36f26da
add context for live provider
umutzd Nov 17, 2021
af199af
rename
umutzd Nov 17, 2021
51b71d5
change resources channel name
umutzd Nov 17, 2021
25bf1b4
use LiveProvider instead of LiveDataProvider
umutzd Nov 17, 2021
5f9b22c
fix used type
umutzd Nov 17, 2021
6c373d9
added provider to refine container
umutzd Nov 18, 2021
fbd781d
add liveProvider as a provider to supabase example
umutzd Nov 18, 2021
91e4837
add useSubscribe
umutzd Nov 19, 2021
cf98911
add supabase live provider
umutzd Nov 24, 2021
f4784a3
add pubnub example
umutzd Nov 25, 2021
b381b42
add params and id subscription
umutzd Nov 25, 2021
63a53c2
add pubnub data provider
umutzd Nov 25, 2021
02d0cc4
add liveParams to useTable
umutzd Nov 25, 2021
0cbee0b
remove unnecessary imports
umutzd Nov 25, 2021
365ccbe
Merge branch 'master' into supabase-realtime
omeraplak Nov 25, 2021
d6f6d69
add id to live params
umutzd Nov 29, 2021
fa4977e
ignore codemod
umutzd Nov 29, 2021
58da015
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Nov 29, 2021
eb459f6
Merge branch 'master' of github.com:pankod/refine into supabase-realtime
umutzd Nov 29, 2021
55e724d
init live provider api reference doc
mhrrmk Nov 29, 2021
e50f7fa
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
mhrrmk Nov 29, 2021
e5b08cc
finalize supabase example
umutzd Nov 29, 2021
57f3d07
add overview, usage, live mode sections to doc
mhrrmk Nov 29, 2021
94ef1a2
add provider methods to doc
mhrrmk Nov 30, 2021
0dcffa0
add controlled live mode to pubnub example
umutzd Nov 30, 2021
59f00be
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Nov 30, 2021
29238c6
add deleted event
umutzd Nov 30, 2021
3b60f98
update pubnub example controlled mode
umutzd Nov 30, 2021
9ff5b56
Merge branch 'master' into supabase-realtime
omeraplak Nov 30, 2021
fe14592
add supported hooks section
mhrrmk Nov 30, 2021
bb33f4d
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
mhrrmk Nov 30, 2021
c863c1f
update pubnub example
umutzd Dec 1, 2021
9168649
update liveMode values and remove useSubscription
umutzd Dec 1, 2021
e8854dd
fix pubnub example
umutzd Dec 1, 2021
c8e3eac
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Dec 1, 2021
f7cff4e
disable liveMode in RefreshButton
umutzd Dec 1, 2021
7af616a
make publish function in LiveProvider optional
umutzd Dec 1, 2021
b8e5cf8
fix pubnub unit tests
omeraplak Dec 1, 2021
9584f62
create real-time guide doc
salihozdemir Dec 1, 2021
3dc51aa
refactor to pubnub example
salihozdemir Dec 1, 2021
a55f557
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
salihozdemir Dec 1, 2021
b4cc009
export PubNub from refine-pubnub package
salihozdemir Dec 1, 2021
d6ec79d
add default custom sider
salihozdemir Dec 2, 2021
c34f69e
add categories resource
salihozdemir Dec 2, 2021
ed00f0c
create useSubscription hook
salihozdemir Dec 2, 2021
47ab833
fix useResourceSubscription props type name
salihozdemir Dec 2, 2021
20c184e
create usePublish hook
salihozdemir Dec 2, 2021
b4283b5
add notification badge to menu item
salihozdemir Dec 2, 2021
811a757
add custom subscriptions section to guide doc
salihozdemir Dec 2, 2021
c5fede5
use id array for publications
umutzd Dec 2, 2021
ffa7ebe
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
salihozdemir Dec 2, 2021
4c05c8a
add ably
salihozdemir Dec 3, 2021
ba28196
fix ably unsubscribe logic
omeraplak Dec 3, 2021
e5e1742
handle params.ids on live
omeraplak Dec 3, 2021
1457349
pubnub convert to ably in example and guide doc
salihozdemir Dec 3, 2021
6e2d61e
rename pubnub to ably
salihozdemir Dec 3, 2021
d616772
finish real time guide
salihozdemir Dec 3, 2021
bd89838
update supabase example
omeraplak Dec 3, 2021
744453d
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
omeraplak Dec 3, 2021
95df807
type to types for liveProvider type property
omeraplak Dec 3, 2021
d6da724
fix unit tests
omeraplak Dec 6, 2021
9104c6b
fix useSelect enabled
omeraplak Dec 6, 2021
e08ef82
add useLiveMode tests
omeraplak Dec 6, 2021
eadb87e
add usePublish tests
omeraplak Dec 6, 2021
9ebbed1
fix example type parameter
umutzd Dec 6, 2021
16b503f
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Dec 6, 2021
2660c2b
add useSubscription tests
omeraplak Dec 6, 2021
0ed2f63
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
omeraplak Dec 6, 2021
4adfd55
add useResourceSubscription tests
omeraplak Dec 6, 2021
dfb7fcd
remove LiveModeContext
umutzd Dec 6, 2021
a0cc903
add types of usePublish
umutzd Dec 6, 2021
507a308
fix tests to remove LiveModeProvider
umutzd Dec 6, 2021
a8889f4
update live provider api reference doc
mhrrmk Dec 6, 2021
11559fa
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
mhrrmk Dec 6, 2021
ec769d8
add useList & useOne useSubscription tests
omeraplak Dec 6, 2021
b3e8375
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
omeraplak Dec 6, 2021
f69d33f
add useMany useSubscription tests
omeraplak Dec 7, 2021
8185d18
add publish unit tests for mutation hooks
omeraplak Dec 7, 2021
bdbeb4e
Update documentation/docs/guides-and-concepts/real-time.md
salihozdemir Dec 7, 2021
a4d8ce5
create usePublish doc
salihozdemir Dec 7, 2021
001ffbc
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
salihozdemir Dec 7, 2021
c782bf9
Update documentation/docs/api-references/hooks/live/usePublish.md
salihozdemir Dec 7, 2021
a3065e2
Update documentation/docs/api-references/hooks/live/usePublish.md
salihozdemir Dec 7, 2021
e77ef0c
Update documentation/docs/api-references/hooks/live/usePublish.md
salihozdemir Dec 7, 2021
398a12e
Update documentation/docs/api-references/hooks/live/usePublish.md
salihozdemir Dec 7, 2021
5272c54
created useSubscription doc
salihozdemir Dec 7, 2021
2fc81fb
add hook links
salihozdemir Dec 7, 2021
3509604
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
salihozdemir Dec 7, 2021
81d6e54
fix highlight bug
salihozdemir Dec 7, 2021
dcd067d
add live mode props to docs
umutzd Dec 7, 2021
22b37e5
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Dec 7, 2021
b41c84a
turn off useMany live mode in useSelect
umutzd Dec 7, 2021
4f143c4
last touches in real time docs
salihozdemir Dec 7, 2021
b587db4
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
salihozdemir Dec 7, 2021
03cb896
delete unused Space component
omeraplak Dec 7, 2021
c37ab75
Merge branch 'supabase-realtime' of https://github.com/pankod/refine …
omeraplak Dec 7, 2021
623ea9e
update livemode link
umutzd Dec 7, 2021
f56973d
Merge branch 'supabase-realtime' of github.com:pankod/refine into sup…
umutzd Dec 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add publish unit tests for mutation hooks
  • Loading branch information
omeraplak committed Dec 7, 2021
commit 8185d18e085019ed359a04562a0a0f0bcfaf7b99
39 changes: 39 additions & 0 deletions packages/core/src/hooks/data/useCreate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,43 @@ describe("useCreate Hook", () => {
expect(status).toBe("success");
expect(data?.data.slug).toBe("ut-ad-et");
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useCreate(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({ resource: "posts", values: { id: 1 } });

await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "created",
payload: {
ids: ["1"],
},
});
});
});
});
42 changes: 42 additions & 0 deletions packages/core/src/hooks/data/useCreateMany.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,46 @@ describe("useCreateMany Hook", () => {
expect(data?.data[0].slug).toBe("ut-ad-et");
expect(data?.data[1].slug).toBe("consequatur-molestiae-rerum");
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useCreateMany(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({
resource: "posts",
values: [{ id: 1 }, { id: 2 }],
});

await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "created",
payload: {
ids: ["1", "2"],
},
});
});
});
});
42 changes: 42 additions & 0 deletions packages/core/src/hooks/data/useDelete.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,46 @@ describe("useDelete Hook", () => {

expect(isSuccess).toBeTruthy();
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useDelete(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({
id: "1",
resource: "posts",
mutationMode: "pessimistic",
});
await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "deleted",
payload: {
ids: ["1"],
},
});
});
});
});
41 changes: 41 additions & 0 deletions packages/core/src/hooks/data/useDeleteMany.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,45 @@ describe("useDeleteMany Hook", () => {

expect(isSuccess).toBeTruthy();
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useDeleteMany(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({
resource: "posts",
ids: ["1", "2"],
});
await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "deleted",
payload: {
ids: ["1", "2"],
},
});
});
});
});
2 changes: 1 addition & 1 deletion packages/core/src/hooks/data/useDeleteMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const useDeleteMany = <
publish?.({
channel: `resources/${resource}`,
type: "deleted",
payload: ids.map(String),
payload: { ids: ids.map(String) },
date: new Date(),
});
},
Expand Down
44 changes: 44 additions & 0 deletions packages/core/src/hooks/data/useUpdate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,48 @@ describe("useUpdate Hook", () => {

expect(isSuccess).toBeTruthy();
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useUpdate(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({
resource: "posts",
mutationMode: "undoable",
undoableTimeout: 0,
id: "1",
values: { id: "1", title: "undoable test" },
});
await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "updated",
payload: {
ids: ["1"],
},
});
});
});
});
44 changes: 44 additions & 0 deletions packages/core/src/hooks/data/useUpdateMany.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,48 @@ describe("useUpdateMany Hook", () => {

expect(isSuccess).toBeTruthy();
});

describe("usePublish", () => {
it("publish live event on success", async () => {
const onPublishMock = jest.fn();

const { result, waitForNextUpdate, waitFor } = renderHook(
() => useUpdateMany(),
{
wrapper: TestWrapper({
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
liveProvider: {
unsubscribe: jest.fn(),
subscribe: jest.fn(),
publish: onPublishMock,
},
}),
},
);

result.current.mutate({
resource: "posts",
mutationMode: "undoable",
undoableTimeout: 0,
ids: ["1", "2"],
values: { id: "1", title: "undoable test" },
});
await waitForNextUpdate();

await waitFor(() => {
return result.current.isSuccess;
});

expect(onPublishMock).toBeCalled();
expect(onPublishMock).toHaveBeenCalledWith({
channel: "resources/posts",
date: expect.any(Date),
type: "updated",
payload: {
ids: ["1", "2"],
},
});
});
});
});
4 changes: 3 additions & 1 deletion packages/core/src/hooks/data/useUpdateMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ export const useUpdateMany = <
publish?.({
channel: `resources/${resource}`,
type: "updated",
payload: ids.map(String),
payload: {
ids: ids.map(String),
},
date: new Date(),
});
},
Expand Down