refactor: Centralized input validation (#142)
* Initial implementaion of service account json, user fraction and status validation * Move validation to input-validation Also created some more validators * Rearrange whatsnew tests to clear out test folder * Return error messages for input validation * Create tests for some validation code * Separate user fraction and status validation * Write more tests and fix some bugs * Refactor to use promises * Fix release file loading from glob
This commit is contained in:
74
__tests__/input-validation.test.ts
Normal file
74
__tests__/input-validation.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { validateInAppUpdatePriority, validateReleaseFiles, validateStatus, validateUserFraction } from "../src/input-validation"
|
||||
|
||||
test("invalid in-app update priority fails validation", async () => {
|
||||
const testValues = [-1, 6, -1000, 1000]
|
||||
for (const value of testValues) {
|
||||
await expect(validateInAppUpdatePriority(value)).rejects.toThrowError()
|
||||
}
|
||||
})
|
||||
|
||||
test("valid in-app update priority passes validation", async () => {
|
||||
const testValues = [0, 1, 2, 3, 4, 5, undefined]
|
||||
for (const value of testValues) {
|
||||
await validateInAppUpdatePriority(value)
|
||||
}
|
||||
})
|
||||
|
||||
test("invalid releaseFiles glob fails validation", async () => {
|
||||
const testValues = ['./__tests__/releasefiles/*.null', `./__tests__/releasefiles/nonexistent-release.aab`]
|
||||
await expect(validateReleaseFiles(testValues)).rejects.toThrowError()
|
||||
})
|
||||
|
||||
test("valid releaseFiles glob passes validation", async () => {
|
||||
const testValues = ['./__tests__/releasefiles/*.aab', `./__tests__/releasefiles/release.aab`]
|
||||
await validateReleaseFiles(testValues)
|
||||
})
|
||||
|
||||
test("fractionless status without fraction passes validation", async () => {
|
||||
const testValues = ['completed', 'draft']
|
||||
for (const value of testValues) {
|
||||
await validateStatus(value, false)
|
||||
}
|
||||
})
|
||||
|
||||
test("fractionless status with fraction fails validation", async () => {
|
||||
const testValues = ['completed', 'draft']
|
||||
for (const value of testValues) {
|
||||
await expect(validateStatus(value, true)).rejects.toThrowError()
|
||||
}
|
||||
})
|
||||
|
||||
test("fractioned status without fraction fails validation", async () => {
|
||||
const testValues = ['inProgress', 'halted']
|
||||
for (const value of testValues) {
|
||||
await expect(validateStatus(value, false)).rejects.toThrowError()
|
||||
}
|
||||
})
|
||||
|
||||
test("fractioned status with fraction passes validation", async () => {
|
||||
const testValues = ['inProgress', 'halted']
|
||||
for (const value of testValues) {
|
||||
await validateStatus(value, true)
|
||||
}
|
||||
})
|
||||
|
||||
test("invalid status fails validation", async () => {
|
||||
const testValues = ['statusGoBrrr', undefined]
|
||||
for (const value of testValues) {
|
||||
await expect(validateStatus(value, true)).rejects.toThrowError()
|
||||
}
|
||||
})
|
||||
|
||||
test("invalid user fraction fails validation", async () => {
|
||||
const testValues = [0, 1, -1, 2, NaN]
|
||||
for (const value of testValues) {
|
||||
await expect(validateUserFraction(value)).rejects.toThrowError()
|
||||
}
|
||||
})
|
||||
|
||||
test("valid user fraction passes validation", async () => {
|
||||
const testValues = [0.1, 0.9, 0.5, undefined]
|
||||
for (const value of testValues) {
|
||||
await validateUserFraction(value)
|
||||
}
|
||||
})
|
||||
0
__tests__/releasefiles/release.aab
Normal file
0
__tests__/releasefiles/release.aab
Normal file
@@ -1,12 +1,7 @@
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as path from 'path'
|
||||
import {readLocalizedReleaseNotes} from "../src/whatsnew";
|
||||
import {androidpublisher_v3} from "@googleapis/androidpublisher";
|
||||
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
||||
|
||||
test("read localized whatsnew files", async () => {
|
||||
let texts = await readLocalizedReleaseNotes("./__tests__");
|
||||
let texts = await readLocalizedReleaseNotes("./__tests__/whatsnew");
|
||||
expect(texts).toHaveLength(6);
|
||||
expect(texts).toContainEqual({
|
||||
language: "en-US",
|
||||
@@ -32,4 +27,4 @@ test("read localized whatsnew files", async () => {
|
||||
language: "et",
|
||||
text: "test_changelog_file_estonian"
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user