refactor: more database types (#17490)
This commit is contained in:
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { Session } from 'src/database';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
||||
import { SessionItem } from 'src/types';
|
||||
|
||||
const authUser = {
|
||||
admin: {
|
||||
@@ -27,7 +27,7 @@ export const authStub = {
|
||||
user: authUser.user1,
|
||||
session: {
|
||||
id: 'token-id',
|
||||
} as SessionItem,
|
||||
} as Session,
|
||||
}),
|
||||
user2: Object.freeze<AuthDto>({
|
||||
user: {
|
||||
@@ -40,7 +40,7 @@ export const authStub = {
|
||||
},
|
||||
session: {
|
||||
id: 'token-id',
|
||||
} as SessionItem,
|
||||
} as Session,
|
||||
}),
|
||||
adminSharedLink: Object.freeze<AuthDto>({
|
||||
user: authUser.admin,
|
||||
|
||||
Vendored
-27
@@ -1,27 +0,0 @@
|
||||
import { SessionItem } from 'src/types';
|
||||
import { userStub } from 'test/fixtures/user.stub';
|
||||
|
||||
export const sessionStub = {
|
||||
valid: Object.freeze<SessionItem>({
|
||||
id: 'token-id',
|
||||
token: 'auth_token',
|
||||
userId: userStub.user1.id,
|
||||
user: userStub.user1,
|
||||
createdAt: new Date('2021-01-01'),
|
||||
updatedAt: new Date(),
|
||||
deviceType: '',
|
||||
deviceOS: '',
|
||||
updateId: 'uuid-v7',
|
||||
}),
|
||||
inactive: Object.freeze<SessionItem>({
|
||||
id: 'not_active',
|
||||
token: 'auth_token',
|
||||
userId: userStub.user1.id,
|
||||
user: userStub.user1,
|
||||
createdAt: new Date('2021-01-01'),
|
||||
updatedAt: new Date('2021-01-01'),
|
||||
deviceType: 'Mobile',
|
||||
deviceOS: 'Android',
|
||||
updateId: 'uuid-v7',
|
||||
}),
|
||||
};
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Library,
|
||||
Memory,
|
||||
Partner,
|
||||
Session,
|
||||
SidecarWriteAsset,
|
||||
User,
|
||||
UserAdmin,
|
||||
@@ -31,7 +32,11 @@ export const newEmbedding = () => {
|
||||
return '[' + embedding + ']';
|
||||
};
|
||||
|
||||
const authFactory = ({ apiKey, ...user }: Partial<AuthUser> & { apiKey?: Partial<AuthApiKey> } = {}) => {
|
||||
const authFactory = ({
|
||||
apiKey,
|
||||
session,
|
||||
...user
|
||||
}: Partial<AuthUser> & { apiKey?: Partial<AuthApiKey>; session?: { id: string } } = {}) => {
|
||||
const auth: AuthDto = {
|
||||
user: authUserFactory(user),
|
||||
};
|
||||
@@ -40,6 +45,10 @@ const authFactory = ({ apiKey, ...user }: Partial<AuthUser> & { apiKey?: Partial
|
||||
auth.apiKey = authApiKeyFactory(apiKey);
|
||||
}
|
||||
|
||||
if (session) {
|
||||
auth.session = { id: session.id };
|
||||
}
|
||||
|
||||
return auth;
|
||||
};
|
||||
|
||||
@@ -76,7 +85,7 @@ const partnerFactory = (partner: Partial<Partner> = {}) => {
|
||||
};
|
||||
};
|
||||
|
||||
const sessionFactory = () => ({
|
||||
const sessionFactory = (session: Partial<Session> = {}) => ({
|
||||
id: newUuid(),
|
||||
createdAt: newDate(),
|
||||
updatedAt: newDate(),
|
||||
@@ -85,6 +94,7 @@ const sessionFactory = () => ({
|
||||
deviceType: 'mobile',
|
||||
token: 'abc123',
|
||||
userId: newUuid(),
|
||||
...session,
|
||||
});
|
||||
|
||||
const stackFactory = () => ({
|
||||
|
||||
Reference in New Issue
Block a user