mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-31 16:57:08 +02:00
test(API): Add tests for UpdateProjectDto (no-changelog) (#16452)
This commit is contained in:
parent
29752ead00
commit
006f22f5c2
|
|
@ -4,13 +4,13 @@ describe('UpdateProjectDto', () => {
|
|||
describe('Valid requests', () => {
|
||||
test.each([
|
||||
{
|
||||
name: 'with just the name',
|
||||
name: 'just the name',
|
||||
request: {
|
||||
name: 'My Updated Project',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'with name and emoji icon',
|
||||
name: 'name and emoji icon',
|
||||
request: {
|
||||
name: 'My Updated Project',
|
||||
icon: {
|
||||
|
|
@ -20,7 +20,7 @@ describe('UpdateProjectDto', () => {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: 'with name and regular icon',
|
||||
name: 'name and regular icon',
|
||||
request: {
|
||||
name: 'My Updated Project',
|
||||
icon: {
|
||||
|
|
@ -30,7 +30,19 @@ describe('UpdateProjectDto', () => {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: 'with relations',
|
||||
name: 'just the description',
|
||||
request: {
|
||||
description: 'My Updated Project Description',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'an empty description',
|
||||
request: {
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'just the relations',
|
||||
request: {
|
||||
relations: [
|
||||
{
|
||||
|
|
@ -41,7 +53,7 @@ describe('UpdateProjectDto', () => {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: 'with all fields',
|
||||
name: 'all fields',
|
||||
request: {
|
||||
name: 'My Updated Project',
|
||||
icon: {
|
||||
|
|
@ -54,9 +66,10 @@ describe('UpdateProjectDto', () => {
|
|||
role: 'project:admin',
|
||||
},
|
||||
],
|
||||
description: 'My Updated Project Description',
|
||||
},
|
||||
},
|
||||
])('should validate $name', ({ request }) => {
|
||||
])('should pass validation for $name', ({ request }) => {
|
||||
const result = UpdateProjectDto.safeParse(request);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
|
@ -69,6 +82,11 @@ describe('UpdateProjectDto', () => {
|
|||
request: { name: 123 },
|
||||
expectedErrorPath: ['name'],
|
||||
},
|
||||
{
|
||||
name: 'empty name',
|
||||
request: { name: '', icon: { type: 'emoji', value: '🚀' } },
|
||||
expectedErrorPath: ['name'],
|
||||
},
|
||||
{
|
||||
name: 'name too long',
|
||||
request: { name: 'a'.repeat(256) },
|
||||
|
|
@ -108,6 +126,16 @@ describe('UpdateProjectDto', () => {
|
|||
},
|
||||
expectedErrorPath: ['relations', 0, 'role'],
|
||||
},
|
||||
{
|
||||
name: 'invalid description type',
|
||||
request: { description: 123 },
|
||||
expectedErrorPath: ['description'],
|
||||
},
|
||||
{
|
||||
name: 'description too long',
|
||||
request: { description: 'a'.repeat(513) },
|
||||
expectedErrorPath: ['description'],
|
||||
},
|
||||
])('should fail validation for $name', ({ request, expectedErrorPath }) => {
|
||||
const result = UpdateProjectDto.safeParse(request);
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ export class ProjectController {
|
|||
@Param('projectId') projectId: string,
|
||||
) {
|
||||
const { name, icon, relations, description } = payload;
|
||||
if ([name, icon, description].some((data) => typeof data === 'string')) {
|
||||
if (name || icon || description) {
|
||||
await this.projectsService.updateProject(projectId, { name, icon, description });
|
||||
}
|
||||
if (relations) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user