Skip to content

Commit c468bfd

Browse files
fix: move checkSlug fn to validate (#990)
1 parent 5b26dbc commit c468bfd

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

src/helpers/checkSlug.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/helpers/validate.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ export function validateSHA(
4646
commitSHA.length === requestedLength && validator.isAlphanumeric(commitSHA)
4747
)
4848
}
49+
50+
export function checkSlug(slug: string): boolean {
51+
if (slug !== '' && !slug.match(/\//)) {
52+
return false
53+
}
54+
return true
55+
}

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import { generateGcovCoverageFiles } from './helpers/gcov'
2828
import { generateSwiftCoverageFiles } from './helpers/swift'
2929
import { generateXcodeCoverageFiles } from './helpers/xcode'
3030
import { argAsArray } from './helpers/util'
31-
import { checkSlug } from './helpers/checkSlug'
32-
import { validateFlags } from './helpers/validate'
31+
import { checkSlug, validateFlags } from './helpers/validate'
3332

3433
/**
3534
*

test/helpers/checkSlug.test.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/helpers/validate.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
import * as validate from '../../src/helpers/validate'
2-
import { DEFAULT_UPLOAD_HOST } from '../../src/helpers/constansts'
3-
import Module from 'module'
4-
5-
// Backup the env
6-
const realEnv = { ...process.env }
72

83
describe('Input Validators', () => {
94
describe('Tokens', () => {
@@ -76,4 +71,30 @@ describe('Input Validators', () => {
7671
).toBe(true)
7772
})
7873
})
74+
75+
describe('checkSlug()', () => {
76+
it('should return true for a slug with a forward slash', () => {
77+
// arrange
78+
const inputSlug = "testOrg/testRepo"
79+
const expectedResult = true
80+
81+
// act
82+
const result = validate.checkSlug(inputSlug)
83+
84+
// assert
85+
expect(result).toEqual(expectedResult)
86+
})
87+
88+
it('should return false for a slug without a forward slash', () => {
89+
// arrange
90+
const inputSlug = 'testRepo'
91+
const expectedResult = false
92+
93+
// act
94+
const result = validate.checkSlug(inputSlug)
95+
96+
// assert
97+
expect(result).toEqual(expectedResult)
98+
})
99+
})
79100
})

0 commit comments

Comments
 (0)