Skip to content
Merged
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
72 changes: 61 additions & 11 deletions __test__/projects/GitHubProjectDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
id: "main",
name: "main",
specifications: [{
id: "foo-service.yml",
name: "foo-service.yml",
url: "/api/blob/acme/foo-openapi/foo-service.yml?ref=12345678",
editURL: "https://github.com/acme/foo-openapi/edit/main/foo-service.yml",
isDefault: false
}, {
id: "bar-service.yml",
name: "bar-service.yml",
url: "/api/blob/acme/foo-openapi/bar-service.yml?ref=12345678",
Expand All @@ -211,6 +205,13 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
url: "/api/blob/acme/foo-openapi/baz-service.yml?ref=12345678",
editURL: "https://github.com/acme/foo-openapi/edit/main/baz-service.yml",
isDefault: false
},
{
id: "foo-service.yml",
name: "foo-service.yml",
url: "/api/blob/acme/foo-openapi/foo-service.yml?ref=12345678",
editURL: "https://github.com/acme/foo-openapi/edit/main/foo-service.yml",
isDefault: false
}],
url: "https://github.com/acme/foo-openapi/tree/main",
isDefault: true
Expand Down Expand Up @@ -663,6 +664,55 @@ test("It prioritizes main, master, develop, and development branch names when so
expect(projects[0].versions[5].name).toEqual("anne")
})

test("It sorts specifications alphabetically", async () => {
const sut = new GitHubProjectDataSource({
repositoryNameSuffix: "-openapi",
repositoryDataSource: {
async getRepositories() {
return [{
owner: "acme",
name: "foo-openapi",
defaultBranchRef: {
id: "12345678",
name: "main"
},
configYaml: {
text: "name: Hello World"
},
branches: [{
id: "12345678",
name: "anne",
files: [{
name: "z-openapi.yml",
}, {
name: "a-openapi.yml",
}, {
name: "1-openapi.yml",
}]
}],
tags: [{
id: "12345678",
name: "cathrine",
files: [{
name: "o-openapi.yml",
}, {
name: "2-openapi.yml",
}]
}]
}]
}
},
encryptionService: noopEncryptionService,
remoteConfigEncoder: base64RemoteConfigEncoder
})
const projects = await sut.getProjects()
expect(projects[0].versions[0].specifications[0].name).toEqual("1-openapi.yml")
expect(projects[0].versions[0].specifications[1].name).toEqual("a-openapi.yml")
expect(projects[0].versions[0].specifications[2].name).toEqual("z-openapi.yml")
expect(projects[0].versions[1].specifications[0].name).toEqual("2-openapi.yml")
expect(projects[0].versions[1].specifications[1].name).toEqual("o-openapi.yml")
})

test("It identifies the default branch in returned versions", async () => {
const sut = new GitHubProjectDataSource({
repositoryNameSuffix: "-openapi",
Expand Down Expand Up @@ -753,15 +803,15 @@ test("It adds remote versions from the project configuration", async () => {
name: "Anne",
isDefault: false,
specifications: [{
id: "huey",
name: "Huey",
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/huey.yml" })}`,
isDefault: false
}, {
id: "dewey",
name: "Dewey",
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/dewey.yml" })}`,
isDefault: false
}, {
id: "huey",
name: "Huey",
url: `/api/remotes/${base64RemoteConfigEncoder.encode({ url: "https://example.com/huey.yml" })}`,
isDefault: false
}]
}, {
id: "bobby",
Expand Down
10 changes: 9 additions & 1 deletion src/features/projects/data/GitHubProjectDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
).filter(version => {
return version.specifications.length > 0
})
.map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName));
.map(version => this.setDefaultSpecification(version, config?.defaultSpecificationName))
.map(version => this.sortSpecificationsByName(version));
const defaultName = repository.name.replace(new RegExp(this.repositoryNameSuffix + "$"), "")
return {
id: `${repository.owner}-${defaultName}`,
Expand Down Expand Up @@ -259,4 +260,11 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
}))
}
}

private sortSpecificationsByName(version: Version): Version {
return {
...version,
specifications: version.specifications.sort((a, b) => a.name.localeCompare(b.name))
}
}
}
Loading