mirror of
https://github.com/caprover/caprover.git
synced 2026-12-04 08:38:19 +00:00
* Fixed https://github.com/caprover/caprover/issues/2112
* Updated changelog
* Force rebuild to capture the frontend change
* Updated changelog
* added fallback ip for installation if public ip not found
* Added project definition to the config
* Added project router
* Updated apps router
* Fixed update path
* Added parent ID for projects
* Typo fix
* Not allow parent to be deleted if there are sub projects
* Fixed typo in string template
* Allow register project to accept description
* Added functionality to remove multiple projects
* Fixed the project deletion
* Fixed the project deletion
* Close https://github.com/caprover/caprover/issues/2153
* Added changelog
* updated changelog
* Updated changelog
* Better error
* Force build
* add MariaDB to README.md
* Improved MacOs startup
* Added theme on backend (#2161)
* Added theme on backend
* Added themes
* Added another theme
* Updated changelog
* Reformat
* Improved dev code
* Improved dev code
* Added another theme
* Updated packages (#2165)
* Updated packages
* Updated packages
* Fixed formatting
* Fixed tests
* Returning project upon creation
* Preparing release
* updated frontend
* Added some test to fix node 20
* Revert "Added some test to fix node 20"
This reverts commit 18a59794b8.
* Updated changelog
---------
Co-authored-by: Robert Silén <robert.silen@mariadb.org>
146 lines
4.5 KiB
TypeScript
146 lines
4.5 KiB
TypeScript
import configstore from 'configstore'
|
|
import AppsDataStore from '../src/datastore/AppsDataStore'
|
|
import ProjectsDataStore from '../src/datastore/ProjectsDataStore'
|
|
import { ProjectDefinition } from '../src/models/ProjectDefinition'
|
|
|
|
describe('ProjectsDataStore', () => {
|
|
let projectsDataStore: ProjectsDataStore
|
|
|
|
beforeEach(() => {
|
|
// Mock the configstore and AppsDataStore
|
|
const mockConfigstore = new configstore('test')
|
|
const mockAppsDataStore = {} as AppsDataStore
|
|
projectsDataStore = new ProjectsDataStore(
|
|
mockConfigstore,
|
|
mockAppsDataStore
|
|
)
|
|
})
|
|
|
|
describe('organizeFromTheLeafsToRoot', () => {
|
|
it('should correctly organize projects from leaves to root', () => {
|
|
const input = [
|
|
{
|
|
id: '1',
|
|
name: 'Root 1',
|
|
parentProjectId: '',
|
|
description: 'Root 1 desc',
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Child 1',
|
|
parentProjectId: '1',
|
|
description: 'Child 1 desc',
|
|
},
|
|
{
|
|
id: '3',
|
|
name: 'Child 2',
|
|
parentProjectId: '1',
|
|
description: 'Child 2 desc',
|
|
},
|
|
{
|
|
id: '4',
|
|
name: 'Grandchild 1',
|
|
parentProjectId: '2',
|
|
description: 'Grandchild 1 desc',
|
|
},
|
|
{
|
|
id: '5',
|
|
name: 'Root 2',
|
|
parentProjectId: '',
|
|
description: 'Root 2 desc',
|
|
},
|
|
{
|
|
id: '6',
|
|
name: 'Child 3',
|
|
parentProjectId: '5',
|
|
description: 'Child 3 desc',
|
|
},
|
|
]
|
|
|
|
const expected = [
|
|
{
|
|
id: '4',
|
|
name: 'Grandchild 1',
|
|
parentProjectId: '2',
|
|
description: 'Grandchild 1 desc',
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Child 1',
|
|
parentProjectId: '1',
|
|
description: 'Child 1 desc',
|
|
},
|
|
{
|
|
id: '3',
|
|
name: 'Child 2',
|
|
parentProjectId: '1',
|
|
description: 'Child 2 desc',
|
|
},
|
|
{
|
|
id: '1',
|
|
name: 'Root 1',
|
|
parentProjectId: '',
|
|
description: 'Root 1 desc',
|
|
},
|
|
{
|
|
id: '6',
|
|
name: 'Child 3',
|
|
parentProjectId: '5',
|
|
description: 'Child 3 desc',
|
|
},
|
|
{
|
|
id: '5',
|
|
name: 'Root 2',
|
|
parentProjectId: '',
|
|
description: 'Root 2 desc',
|
|
},
|
|
]
|
|
|
|
const result = projectsDataStore.organizeFromTheLeafsToRoot(input)
|
|
|
|
expect(result).toEqual(expected)
|
|
})
|
|
|
|
it('should handle empty input', () => {
|
|
const input: ProjectDefinition[] = []
|
|
const result = projectsDataStore.organizeFromTheLeafsToRoot(input)
|
|
expect(result).toEqual([])
|
|
})
|
|
|
|
it('should handle projects with no parent', () => {
|
|
const input = [
|
|
{
|
|
id: '1',
|
|
name: 'Root 1',
|
|
parentProjectId: '',
|
|
description: 'Root 1 desc',
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Root 2',
|
|
parentProjectId: '',
|
|
description: 'Root 2 desc',
|
|
},
|
|
]
|
|
|
|
const expected = [
|
|
{
|
|
id: '1',
|
|
name: 'Root 1',
|
|
parentProjectId: '',
|
|
description: 'Root 1 desc',
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Root 2',
|
|
parentProjectId: '',
|
|
description: 'Root 2 desc',
|
|
},
|
|
]
|
|
|
|
const result = projectsDataStore.organizeFromTheLeafsToRoot(input)
|
|
expect(result).toEqual(expected)
|
|
})
|
|
})
|
|
})
|