mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
fix(core): missing some commits (#444)
This commit is contained in:
parent
847e018b02
commit
04ba181a64
4 changed files with 37 additions and 39 deletions
|
@ -1,11 +1,9 @@
|
|||
import { SignInExperiences } from '@logto/schemas';
|
||||
import { createMockPool, createMockQueryResult, sql } from 'slonik';
|
||||
import { createMockPool, createMockQueryResult } from 'slonik';
|
||||
|
||||
import { convertToIdentifiers } from '@/database/utils';
|
||||
import { mockSignInExperience } from '@/utils/mock';
|
||||
import { expectSqlAssert, QueryType } from '@/utils/test-utils';
|
||||
|
||||
import { findDefaultSignInExperience, updateSignInExperienceById } from './sign-in-experience';
|
||||
import { findDefaultSignInExperience, updateDefaultSignInExperience } from './sign-in-experience';
|
||||
|
||||
const mockQuery: jest.MockedFunction<QueryType> = jest.fn();
|
||||
|
||||
|
@ -18,7 +16,8 @@ jest.mock('@/database/pool', () =>
|
|||
);
|
||||
|
||||
describe('sign-in-experience query', () => {
|
||||
const { table, fields } = convertToIdentifiers(SignInExperiences);
|
||||
const id = 'default';
|
||||
|
||||
const dbvalue = {
|
||||
...mockSignInExperience,
|
||||
branding: JSON.stringify(mockSignInExperience.branding),
|
||||
|
@ -29,14 +28,17 @@ describe('sign-in-experience query', () => {
|
|||
};
|
||||
|
||||
it('findDefaultSignInExperience', async () => {
|
||||
const expectSql = sql`
|
||||
select ${sql.join(Object.values(fields), sql`, `)}
|
||||
from ${table}
|
||||
/* eslint-disable sql/no-unsafe-query */
|
||||
const expectSql = `
|
||||
select "id", "branding", "language_info", "terms_of_use", "forget_password_enabled", "sign_in_methods", "social_sign_in_connector_ids"
|
||||
from "sign_in_experiences"
|
||||
where "id" = $1
|
||||
`;
|
||||
/* eslint-enable sql/no-unsafe-query */
|
||||
|
||||
mockQuery.mockImplementationOnce(async (sql, values) => {
|
||||
expectSqlAssert(sql, expectSql.sql);
|
||||
expect(values).toEqual([]);
|
||||
expectSqlAssert(sql, expectSql);
|
||||
expect(values).toEqual([id]);
|
||||
|
||||
return createMockQueryResult([dbvalue]);
|
||||
});
|
||||
|
@ -44,28 +46,29 @@ describe('sign-in-experience query', () => {
|
|||
await expect(findDefaultSignInExperience()).resolves.toEqual(dbvalue);
|
||||
});
|
||||
|
||||
it('updateSignInExperienceById', async () => {
|
||||
const id = 'foo';
|
||||
it('updateDefaultSignInExperience', async () => {
|
||||
const termsOfUse = {
|
||||
enabled: false,
|
||||
};
|
||||
|
||||
const expectSql = sql`
|
||||
update ${table}
|
||||
/* eslint-disable sql/no-unsafe-query */
|
||||
const expectSql = `
|
||||
update "sign_in_experiences"
|
||||
set
|
||||
${fields.termsOfUse}=
|
||||
coalesce(${fields.termsOfUse},'{}'::jsonb)|| $1
|
||||
where ${fields.id}=$2
|
||||
"terms_of_use"=
|
||||
coalesce("terms_of_use",'{}'::jsonb)|| $1
|
||||
where "id"=$2
|
||||
returning *
|
||||
`;
|
||||
/* eslint-enable sql/no-unsafe-query */
|
||||
|
||||
mockQuery.mockImplementationOnce(async (sql, values) => {
|
||||
expectSqlAssert(sql, expectSql.sql);
|
||||
expectSqlAssert(sql, expectSql);
|
||||
expect(values).toEqual([JSON.stringify(termsOfUse), id]);
|
||||
|
||||
return createMockQueryResult([dbvalue]);
|
||||
});
|
||||
|
||||
await expect(updateSignInExperienceById(id, { termsOfUse })).resolves.toEqual(dbvalue);
|
||||
await expect(updateDefaultSignInExperience({ termsOfUse })).resolves.toEqual(dbvalue);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,13 +13,14 @@ const updateSignInExperience = buildUpdateWhere<CreateSignInExperience, SignInEx
|
|||
true
|
||||
);
|
||||
|
||||
export const updateSignInExperienceById = async (
|
||||
id: string,
|
||||
set: Partial<CreateSignInExperience>
|
||||
) => updateSignInExperience({ set, where: { id } });
|
||||
const id = 'default';
|
||||
|
||||
export const updateDefaultSignInExperience = async (set: Partial<CreateSignInExperience>) =>
|
||||
updateSignInExperience({ set, where: { id } });
|
||||
|
||||
export const findDefaultSignInExperience = async () =>
|
||||
pool.one<SignInExperience>(sql`
|
||||
select ${sql.join(Object.values(fields), sql`, `)}
|
||||
from ${table}
|
||||
where ${fields.id} = ${id}
|
||||
`);
|
||||
|
|
|
@ -12,8 +12,8 @@ jest.mock('@/connectors', () => ({
|
|||
|
||||
jest.mock('@/queries/sign-in-experience', () => ({
|
||||
findDefaultSignInExperience: jest.fn(async (): Promise<SignInExperience> => mockSignInExperience),
|
||||
updateSignInExperienceById: jest.fn(
|
||||
async (_, data: Partial<CreateSignInExperience>): Promise<SignInExperience> => ({
|
||||
updateDefaultSignInExperience: jest.fn(
|
||||
async (data: Partial<CreateSignInExperience>): Promise<SignInExperience> => ({
|
||||
...mockSignInExperience,
|
||||
...data,
|
||||
})
|
||||
|
@ -29,7 +29,7 @@ describe('signInExperiences routes', () => {
|
|||
expect(response.body).toEqual(mockSignInExperience);
|
||||
});
|
||||
|
||||
it('PATCH /sign-in-exp/:id', async () => {
|
||||
it('PATCH /sign-in-exp', async () => {
|
||||
const branding: Branding = {
|
||||
primaryColor: '#000',
|
||||
backgroundColor: '#fff',
|
||||
|
@ -43,7 +43,7 @@ describe('signInExperiences routes', () => {
|
|||
|
||||
const socialSignInConnectorIds = ['abc', 'def'];
|
||||
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp/default').send({
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
branding,
|
||||
socialSignInConnectorIds,
|
||||
});
|
||||
|
@ -56,10 +56,10 @@ describe('signInExperiences routes', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('PATCH /sign-in-exp/:id should throw with invalid inputs', async () => {
|
||||
it('PATCH /sign-in-exp should throw with invalid inputs', async () => {
|
||||
const socialSignInConnectorIds = [123, 456];
|
||||
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp/default').send({
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
socialSignInConnectorIds,
|
||||
});
|
||||
expect(response.status).toEqual(400);
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { SignInExperiences } from '@logto/schemas';
|
||||
import { object, string } from 'zod';
|
||||
|
||||
import { getEnabledSocialConnectorIds } from '@/connectors';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import {
|
||||
findDefaultSignInExperience,
|
||||
updateSignInExperienceById,
|
||||
updateDefaultSignInExperience,
|
||||
} from '@/queries/sign-in-experience';
|
||||
|
||||
import { AuthedRouter } from './types';
|
||||
|
@ -36,20 +35,15 @@ export default function signInExperiencesRoutes<T extends AuthedRouter>(router:
|
|||
return next();
|
||||
});
|
||||
|
||||
// TODO: LOG-1403 need to find a way to validate SignInMethod input
|
||||
router.patch(
|
||||
'/sign-in-exp/:id',
|
||||
'/sign-in-exp',
|
||||
koaGuard({
|
||||
params: object({ id: string().min(1) }),
|
||||
body: SignInExperiences.createGuard.omit({ id: true }).partial(),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { id },
|
||||
body,
|
||||
} = ctx.guard;
|
||||
const { body } = ctx.guard;
|
||||
|
||||
ctx.body = await updateSignInExperienceById(id, {
|
||||
ctx.body = await updateDefaultSignInExperience({
|
||||
...body,
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue