-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): set user default roles from env (#1793)
- Loading branch information
Showing
13 changed files
with
87 additions
and
75 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
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
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 |
---|---|---|
|
@@ -7,23 +7,26 @@ import { createRequester } from '@/utils/test-utils'; | |
|
||
import sessionPasswordlessRoutes from './passwordless'; | ||
|
||
const insertUser = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const findUserById = jest.fn(async (): Promise<User> => mockUser); | ||
const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
|
||
jest.mock('@/lib/user', () => ({ | ||
generateUserId: () => 'user1', | ||
updateLastSignInAt: async (...args: unknown[]) => updateUserById(...args), | ||
insertUser: async (...args: unknown[]) => insertUser(...args), | ||
})); | ||
const insertUser = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const findUserById = jest.fn(async (): Promise<User> => mockUser); | ||
const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
|
||
jest.mock('@/queries/user', () => ({ | ||
findUserById: async () => findUserById(), | ||
findUserByPhone: async () => ({ id: 'id' }), | ||
findUserByEmail: async () => ({ id: 'id' }), | ||
insertUser: async (...args: unknown[]) => insertUser(...args), | ||
updateUserById: async (...args: unknown[]) => updateUserById(...args), | ||
hasUser: async (username: string) => username === 'username1', | ||
hasUserWithPhone: async (phone: string) => phone === '13000000000', | ||
hasUserWithEmail: async (email: string) => email === '[email protected]', | ||
})); | ||
|
||
const sendPasscode = jest.fn(async () => ({ connector: { id: 'connectorIdValue' } })); | ||
jest.mock('@/lib/passcode', () => ({ | ||
createPasscode: async () => ({ id: 'id' }), | ||
|
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 |
---|---|---|
|
@@ -8,6 +8,25 @@ import { createRequester } from '@/utils/test-utils'; | |
|
||
import sessionRoutes from './session'; | ||
|
||
const insertUser = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const findUserById = jest.fn(async (): Promise<User> => mockUser); | ||
const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const hasActiveUsers = jest.fn(async () => true); | ||
|
||
jest.mock('@/queries/user', () => ({ | ||
findUserById: async () => findUserById(), | ||
findUserByIdentity: async () => ({ id: 'id', identities: {} }), | ||
findUserByPhone: async () => ({ id: 'id' }), | ||
findUserByEmail: async () => ({ id: 'id' }), | ||
updateUserById: async (...args: unknown[]) => updateUserById(...args), | ||
hasUser: async (username: string) => username === 'username1', | ||
hasUserWithIdentity: async (connectorId: string, userId: string) => | ||
connectorId === 'connectorId' && userId === 'id', | ||
hasUserWithPhone: async (phone: string) => phone === '13000000000', | ||
hasUserWithEmail: async (email: string) => email === '[email protected]', | ||
hasActiveUsers: async () => hasActiveUsers(), | ||
})); | ||
|
||
jest.mock('@/lib/user', () => ({ | ||
async findUserByUsernameAndPassword(username: string, password: string) { | ||
if (username !== 'username' && username !== 'admin') { | ||
|
@@ -28,25 +47,7 @@ jest.mock('@/lib/user', () => ({ | |
passwordEncryptionMethod: 'Argon2i', | ||
}), | ||
updateLastSignInAt: async (...args: unknown[]) => updateUserById(...args), | ||
})); | ||
const insertUser = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const findUserById = jest.fn(async (): Promise<User> => mockUser); | ||
const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' })); | ||
const hasActiveUsers = jest.fn(async () => true); | ||
|
||
jest.mock('@/queries/user', () => ({ | ||
findUserById: async () => findUserById(), | ||
findUserByIdentity: async () => ({ id: 'id', identities: {} }), | ||
findUserByPhone: async () => ({ id: 'id' }), | ||
findUserByEmail: async () => ({ id: 'id' }), | ||
insertUser: async (...args: unknown[]) => insertUser(...args), | ||
updateUserById: async (...args: unknown[]) => updateUserById(...args), | ||
hasUser: async (username: string) => username === 'username1', | ||
hasUserWithIdentity: async (connectorId: string, userId: string) => | ||
connectorId === 'connectorId' && userId === 'id', | ||
hasUserWithPhone: async (phone: string) => phone === '13000000000', | ||
hasUserWithEmail: async (email: string) => email === '[email protected]', | ||
hasActiveUsers: async () => hasActiveUsers(), | ||
})); | ||
|
||
const grantSave = jest.fn(async () => 'finalGrantId'); | ||
|
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