-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move code into separate files and separate concerns a bit better, avo…
…id a extra GraphQL request
- Loading branch information
Showing
5 changed files
with
247 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {mustGetOwnerTypeQuery, parseProjectName} from '../src/utils' | ||
|
||
describe('mustGetOwnerTypeQuery', () => { | ||
test('returns organization for orgs ownerType', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('orgs') | ||
|
||
expect(ownerTypeQuery).toEqual('organization') | ||
}) | ||
|
||
test('returns organization for empty ownerType', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery() | ||
|
||
expect(ownerTypeQuery).toEqual('organization') | ||
}) | ||
|
||
test('returns organization for org ownerType', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('org') | ||
|
||
expect(ownerTypeQuery).toEqual('organization') | ||
}) | ||
|
||
test('returns organization for organizations ownerType', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('organizations') | ||
|
||
expect(ownerTypeQuery).toEqual('organization') | ||
}) | ||
|
||
test('returns organization for wrong case in param', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('Organizations') | ||
|
||
expect(ownerTypeQuery).toEqual('organization') | ||
}) | ||
|
||
test('returns user for users ownerType', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('users') | ||
|
||
expect(ownerTypeQuery).toEqual('user') | ||
}) | ||
|
||
test('returns user for wrong case in param', async () => { | ||
const ownerTypeQuery = mustGetOwnerTypeQuery('uSeRs') | ||
|
||
expect(ownerTypeQuery).toEqual('user') | ||
}) | ||
|
||
test('throws an error when an unsupported ownerType is set', async () => { | ||
expect(() => { | ||
mustGetOwnerTypeQuery('unknown') | ||
}).toThrow( | ||
`Unsupported ownerType: unknown. Must be one of 'orgs', 'organization', 'org', 'organizations' or 'users', 'user'`, | ||
) | ||
}) | ||
}) | ||
|
||
describe('parseProjectName', () => { | ||
test('returns the given branch without changes when no param', async () => { | ||
const baseBranch = 'main' | ||
const projectName = parseProjectName({baseBranch}) | ||
|
||
expect(projectName).toEqual('main') | ||
}) | ||
|
||
test('returns the given branch without the prefix when a prefixRemove is passed', async () => { | ||
const baseBranch = 'feature/work' | ||
const prefixRemove = 'feature/' | ||
const projectName = parseProjectName({baseBranch, prefixRemove}) | ||
|
||
expect(projectName).toEqual('work') | ||
}) | ||
|
||
test('returns the given branch without the suffix when a suffixRemove is passed', async () => { | ||
const baseBranch = 'feature/work' | ||
const sufixRemove = '/work' | ||
const projectName = parseProjectName({baseBranch, sufixRemove}) | ||
|
||
expect(projectName).toEqual('feature') | ||
}) | ||
|
||
test('returns the given branch with the a set of chars replaced by spaces', async () => { | ||
const baseBranch = 'feature-work-branch_issue' | ||
const replaceWithSpaces = '-_' | ||
const projectName = parseProjectName({baseBranch, replaceWithSpaces}) | ||
|
||
expect(projectName).toEqual('feature work branch issue') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.