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

chore(test): add http strategy tests #8699

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions packages/adapter-surrealdb/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const config = (
db: {
async disconnect() {
const surreal = await clientPromise
try {
await surreal.delete("account")
await surreal.delete("session")
await surreal.delete("verification_token")
} catch (e) {
console.log(e)
}
console.log("closing")
if (surreal.close) surreal.close()
},
async user(id: string) {
Expand Down
30 changes: 26 additions & 4 deletions packages/adapter-surrealdb/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import Surreal from "surrealdb.js"
import Surreal, { ExperimentalSurrealHTTP } from "surrealdb.js"
import { runBasicTests } from "@auth/adapter-test"
import fetch from "node-fetch"

Copy link
Member

Choose a reason for hiding this comment

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

can we not use node-fetch here? tests were passing for me even without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this PR we need to wait for surrealdb.js to merge this other PR: surrealdb/surrealdb.js#171

I tested it using my fork with the fix

Copy link
Member

@balazsorban44 balazsorban44 Sep 26, 2023

Choose a reason for hiding this comment

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

Suggested change
import fetch from "node-fetch"

node-fetch (or any other fetch polyfill) indeed is not necessary anymore, as all Node.js versions have fetch already available.

import { config } from "./common"

const clientPromise = new Promise<Surreal>(async (resolve, reject) => {
const db = new Surreal();
const db = new Surreal()
try {
await db.connect('http://0.0.0.0:8000/rpc', {
await db.connect("http://0.0.0.0:8000/rpc", {
ns: "test",
db: "test",
auth: {
user: "test",
pass: "test",
}
},
})
resolve(db)
} catch (e) {
Expand All @@ -21,3 +22,24 @@ const clientPromise = new Promise<Surreal>(async (resolve, reject) => {
})

runBasicTests(config(clientPromise))

const clientPromiseRest = new Promise<ExperimentalSurrealHTTP<typeof fetch>>(
async (resolve, reject) => {
try {
const db = new ExperimentalSurrealHTTP("http://0.0.0.0:8000", {
fetch,
auth: {
user: "test",
pass: "test",
},
ns: "test",
db: "test",
})
resolve(db)
} catch (e) {
reject(e)
}
}
)

runBasicTests(config(clientPromiseRest))
27 changes: 0 additions & 27 deletions packages/adapter-surrealdb/tests/rest.test.ts

This file was deleted.

Loading