-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: UUID auto generate; Error handling & e2e tests (#1172)
- Loading branch information
1 parent
60a0999
commit ded1651
Showing
7 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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
10 changes: 10 additions & 0 deletions
10
lib/realtime/tenants/repo/migrations/20241019105805_uuid_auto_generation.ex
This file contains 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,10 @@ | ||
defmodule Realtime.Tenants.Migrations.UuidAutoGeneration do | ||
@moduledoc false | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:messages) do | ||
modify :uuid, :uuid, null: false, default: fragment("gen_random_uuid()") | ||
end | ||
end | ||
end |
This file contains 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 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 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 |
---|---|---|
|
@@ -120,7 +120,11 @@ describe("broadcast extension", () => { | |
describe("postgres changes extension", () => { | ||
it("user is able to receive INSERT only events from a subscribed table with filter applied", async () => { | ||
let supabase = await createClient(url, token, { realtime }); | ||
let accessToken = await signInUser(supabase, "[email protected]", "test_test"); | ||
let accessToken = await signInUser( | ||
supabase, | ||
"[email protected]", | ||
"test_test" | ||
); | ||
await supabase.realtime.setAuth(accessToken); | ||
|
||
let result: Array<any> = []; | ||
|
@@ -155,7 +159,11 @@ describe("postgres changes extension", () => { | |
|
||
it("user is able to receive UPDATE only events from a subscribed table with filter applied", async () => { | ||
let supabase = await createClient(url, token, { realtime }); | ||
let accessToken = await signInUser(supabase, "[email protected]", "test_test"); | ||
let accessToken = await signInUser( | ||
supabase, | ||
"[email protected]", | ||
"test_test" | ||
); | ||
await supabase.realtime.setAuth(accessToken); | ||
|
||
let result: Array<any> = []; | ||
|
@@ -194,7 +202,11 @@ describe("postgres changes extension", () => { | |
|
||
it("user is able to receive DELETE only events from a subscribed table with filter applied", async () => { | ||
let supabase = await createClient(url, token, { realtime }); | ||
let accessToken = await signInUser(supabase, "[email protected]", "test_test"); | ||
let accessToken = await signInUser( | ||
supabase, | ||
"[email protected]", | ||
"test_test" | ||
); | ||
await supabase.realtime.setAuth(accessToken); | ||
|
||
let result: Array<any> = []; | ||
|
@@ -258,7 +270,11 @@ describe("authorization check", () => { | |
|
||
it("user using private channel can connect if they have enough permissions", async () => { | ||
let supabase = await createClient(url, token, { realtime }); | ||
let accessToken = await signInUser(supabase, "[email protected]", "test_test"); | ||
let accessToken = await signInUser( | ||
supabase, | ||
"[email protected]", | ||
"test_test" | ||
); | ||
await supabase.realtime.setAuth(accessToken); | ||
|
||
const channel = supabase | ||
|
@@ -275,11 +291,16 @@ describe("authorization check", () => { | |
|
||
describe("broadcast changes", () => { | ||
const table = "broadcast_changes"; | ||
const id = 1; | ||
const id = crypto.randomUUID(); | ||
|
||
it("authenticated user receives insert broadcast change from a specific topic based on id", async () => { | ||
let supabase = await createClient(url, token, { realtime }); | ||
let accessToken = await signInUser(supabase, "[email protected]", "test_test"); | ||
let accessToken = await signInUser( | ||
supabase, | ||
"[email protected]", | ||
"test_test" | ||
); | ||
console.log(accessToken); | ||
await supabase.realtime.setAuth(accessToken); | ||
|
||
let insertResult: any, updateResult: any, deleteResult: any; | ||
|
@@ -288,38 +309,38 @@ describe("broadcast changes", () => { | |
.on("broadcast", { event: "INSERT" }, (res) => (insertResult = res)) | ||
.on("broadcast", { event: "DELETE" }, (res) => (deleteResult = res)) | ||
.on("broadcast", { event: "UPDATE" }, (res) => (updateResult = res)) | ||
.subscribe(); | ||
await sleep(2); | ||
.subscribe((status, err) => console.log({ status, err })); | ||
await sleep(1); | ||
const originalValue = crypto.randomUUID(); | ||
const updatedValue = crypto.randomUUID(); | ||
|
||
await supabase.from(table).insert({ value: originalValue, id: 1 }); | ||
await supabase.from(table).insert({ value: originalValue, id }); | ||
await supabase.from(table).update({ value: updatedValue }).eq("id", id); | ||
await supabase.from(table).delete().eq("id", id); | ||
|
||
await supabase.auth.signOut(); | ||
await stopClient(supabase, [channel]); | ||
|
||
assertEquals(insertResult.payload.record.id, 1); | ||
await sleep(1); | ||
assertEquals(insertResult.payload.record.id, id); | ||
assertEquals(insertResult.payload.record.value, originalValue); | ||
assertEquals(insertResult.payload.old_record, null); | ||
assertEquals(insertResult.payload.operation, "INSERT"); | ||
assertEquals(insertResult.payload.schema, "public"); | ||
assertEquals(insertResult.payload.table, "broadcast_changes"); | ||
|
||
assertEquals(updateResult.payload.record.id, 1); | ||
assertEquals(updateResult.payload.record.id, id); | ||
assertEquals(updateResult.payload.record.value, updatedValue); | ||
assertEquals(updateResult.payload.old_record.id, 1); | ||
assertEquals(updateResult.payload.old_record.id, id); | ||
assertEquals(updateResult.payload.old_record.value, originalValue); | ||
assertEquals(updateResult.payload.operation, "UPDATE"); | ||
assertEquals(updateResult.payload.schema, "public"); | ||
assertEquals(updateResult.payload.table, "broadcast_changes"); | ||
|
||
assertEquals(deleteResult.payload.record, null); | ||
assertEquals(deleteResult.payload.old_record.id, 1); | ||
assertEquals(deleteResult.payload.old_record.id, id); | ||
assertEquals(deleteResult.payload.old_record.value, updatedValue); | ||
assertEquals(deleteResult.payload.operation, "DELETE"); | ||
assertEquals(deleteResult.payload.schema, "public"); | ||
assertEquals(deleteResult.payload.table, "broadcast_changes"); | ||
|
||
await supabase.auth.signOut(); | ||
await stopClient(supabase, [channel]); | ||
}); | ||
}); |