Skip to content

Commit a6bd108

Browse files
georgRusanovgeorgiy.rusanovCopilot
authored
chore(tests): added tests (#1066)
## What kind of change does this PR introduce? It increases test coverage --------- Co-authored-by: georgiy.rusanov <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent e7b2f21 commit a6bd108

File tree

3 files changed

+683
-78
lines changed

3 files changed

+683
-78
lines changed

test/GoTrueApi.test.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('GoTrueAdminApi', () => {
9494
})
9595
})
9696

97-
describe('User fetch', () => {
97+
describe('List users', () => {
9898
test('listUsers() should return registered users', async () => {
9999
const { email } = mockUserCredentials()
100100
const { error: createError, data: createdUser } = await createNewUserWithEmail({ email })
@@ -114,6 +114,18 @@ describe('GoTrueAdminApi', () => {
114114
expect(emails).toContain(email)
115115
})
116116

117+
test('listUsers() returns AuthError when page is invalid', async () => {
118+
const { error, data } = await serviceRoleApiClient.listUsers({
119+
page: -1,
120+
perPage: 10,
121+
})
122+
123+
expect(error).not.toBeNull()
124+
expect(data.users).toEqual([])
125+
})
126+
})
127+
128+
describe('Get user', () => {
117129
test('getUser() fetches a user by their access_token', async () => {
118130
const { email, password } = mockUserCredentials()
119131
const { error: initialError, data } = await authClientWithSession.signUp({
@@ -435,6 +447,27 @@ describe('GoTrueAdminApi', () => {
435447

436448
expect(error?.message).toMatch(/^invalid JWT/)
437449
})
450+
451+
test('signOut() fails with invalid scope', async () => {
452+
const { email, password } = mockUserCredentials()
453+
454+
const { error: signUpError } = await authClientWithSession.signUp({
455+
email,
456+
password,
457+
})
458+
expect(signUpError).toBeNull()
459+
460+
const { data: { session }, error } = await authClientWithSession.signInWithPassword({
461+
email,
462+
password,
463+
})
464+
expect(error).toBeNull()
465+
expect(session).not.toBeNull()
466+
467+
await expect(authClientWithSession.signOut({ scope: 'invalid_scope' as any })).rejects.toThrow(
468+
'@supabase/auth-js: Parameter scope must be one of global, local, others'
469+
)
470+
})
438471
})
439472
})
440473

@@ -475,18 +508,6 @@ describe('GoTrueAdminApi', () => {
475508
})
476509
})
477510

478-
describe('List Users', () => {
479-
test('listUsers() returns AuthError when page is invalid', async () => {
480-
const { error, data } = await serviceRoleApiClient.listUsers({
481-
page: -1,
482-
perPage: 10,
483-
})
484-
485-
expect(error).not.toBeNull()
486-
expect(data.users).toEqual([])
487-
})
488-
})
489-
490511
describe('Update User', () => {
491512
test('updateUserById() returns AuthError when user id is invalid', async () => {
492513
const { error, data } = await serviceRoleApiClient.updateUserById(NON_EXISTANT_USER_ID, {

0 commit comments

Comments
 (0)