Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ProjectSummary } from 'common/types/responses'
import { newestProject } from 'components/pages/onboarding/bootstrap/onboardingProject'

const project = (id: number): ProjectSummary => ({ id } as ProjectSummary)

describe('newestProject', () => {
it('takes the project the user just created, not the first returned', () => {
const created = project(9)
expect(newestProject([project(2), created, project(5)])).toBe(created)
})

it('takes the only project there is', () => {
const only = project(3)
expect(newestProject([only])).toBe(only)
})

it('finds nothing in an organisation with no projects', () => {
expect(newestProject([])).toBeUndefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
findOnboardingTag,
shouldSeedDemoFlag,
} from './demoFlag'
import { newestProject } from './onboardingProject'
import { SmartDefaults } from 'components/pages/onboarding/hooks/useSmartDefaults'
import { createOrganisationViaAccountStore } from './createOrganisationViaAccountStore'
import API from 'project/api'
Expand Down Expand Up @@ -81,7 +82,7 @@ async function ensureProject(
const projects = await store
.dispatch(projectService.endpoints.getProjects.initiate({ organisationId }))
.unwrap()
const existing = projects?.[0]
const existing = newestProject(projects ?? [])
if (existing) {
return existing
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ProjectSummary } from 'common/types/responses'

// The project the user just made: creating one and clicking Getting Started is
// how you run onboarding again. The list comes back in no useful order, so go
// by id rather than position.
export const newestProject = (
projects: ProjectSummary[],
): ProjectSummary | undefined =>
projects.reduce<ProjectSummary | undefined>(
(newest, project) => (!newest || project.id > newest.id ? project : newest),
undefined,
)
Loading