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