-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ adding unit test cases for the application
- Loading branch information
Showing
10 changed files
with
2,520 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ node_modules/ | |
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
coverage/ | ||
|
||
# next.js | ||
.next/ | ||
|
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
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
46 changes: 46 additions & 0 deletions
46
packages/utils/src/functions/string-util/test/isBase64Image.early.test.ts
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,46 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { isBase64Image } from '..'; | ||
|
||
describe('isBase64Image() isBase64Image method', () => { | ||
describe('Happy Paths', () => { | ||
it('should return true for a valid base64 encoded image string', () => { | ||
const validBase64Image = | ||
'iVBORw0KGgoAAAANSUhEUgAAAAUA' + | ||
'AAAFCAYAAACNbyblAAAAHElEQVQI12P4' + | ||
'//8/w38GIAXDIBKE0DHxgljNBAAO' + | ||
'9TXL0Y4OHwAAAABJRU5ErkJggg=='; | ||
expect(isBase64Image(validBase64Image)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Edge Cases', () => { | ||
it('should return false for an empty string', () => { | ||
expect(isBase64Image('')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with invalid base64 characters', () => { | ||
const invalidBase64 = 'This is not a base64 string!'; | ||
expect(isBase64Image(invalidBase64)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string that is not properly padded', () => { | ||
const improperlyPaddedBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAUA'; | ||
expect(isBase64Image(improperlyPaddedBase64)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string that decodes to non-image data', () => { | ||
const base64NonImage = btoa('Hello, World!'); | ||
expect(isBase64Image(base64NonImage)).toBe(false); | ||
}); | ||
|
||
it('should return false for a null input', () => { | ||
expect(isBase64Image(null as unknown as string)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with whitespace', () => { | ||
const base64WithWhitespace = | ||
'iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; | ||
expect(isBase64Image(base64WithWhitespace)).toBe(false); | ||
}); | ||
}); | ||
}); |
73 changes: 73 additions & 0 deletions
73
packages/utils/src/functions/string-util/test/isJson.early.test.ts
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,73 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { isJson } from '..'; | ||
|
||
describe('isJson() isJson method', () => { | ||
describe('Happy Paths', () => { | ||
it('should return true for a valid JSON object', () => { | ||
const jsonString = '{"name": "John", "age": 30}'; | ||
expect(isJson(jsonString)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid JSON array', () => { | ||
const jsonArray = '[1, 2, 3, 4]'; | ||
expect(isJson(jsonArray)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid JSON string', () => { | ||
const jsonString = '"Hello, World!"'; | ||
expect(isJson(jsonString)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid JSON number', () => { | ||
const jsonNumber = '12345'; | ||
expect(isJson(jsonNumber)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid JSON boolean', () => { | ||
const jsonBoolean = 'true'; | ||
expect(isJson(jsonBoolean)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid JSON null', () => { | ||
const jsonNull = 'null'; | ||
expect(isJson(jsonNull)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Edge Cases', () => { | ||
it('should return false for an empty string', () => { | ||
const emptyString = ''; | ||
expect(isJson(emptyString)).toBe(false); | ||
}); | ||
|
||
it('should return false for a malformed JSON string', () => { | ||
const malformedJson = '{"name": "John", "age": 30'; | ||
expect(isJson(malformedJson)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string that is not JSON', () => { | ||
const notJson = 'Hello, World!'; | ||
expect(isJson(notJson)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with only whitespace', () => { | ||
const whitespaceString = ' '; | ||
expect(isJson(whitespaceString)).toBe(false); | ||
}); | ||
|
||
it('should return false for a number that is not a JSON string', () => { | ||
const numberString = '123abc'; | ||
expect(isJson(numberString)).toBe(false); | ||
}); | ||
|
||
it('should return false for a boolean that is not a JSON string', () => { | ||
const booleanString = 'True'; | ||
expect(isJson(booleanString)).toBe(false); | ||
}); | ||
|
||
it('should return false for a null that is not a JSON string', () => { | ||
const nullString = 'Null'; | ||
expect(isJson(nullString)).toBe(false); | ||
}); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/utils/src/functions/string-util/test/isXml.early.test.ts
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,62 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { isXml } from '..'; | ||
|
||
describe('isXml() isXml method', () => { | ||
describe('Happy paths', () => { | ||
it('should return true for a valid XML string', () => { | ||
const validXml = | ||
"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"; | ||
expect(isXml(validXml)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid XML string with namespaces', () => { | ||
const validXmlWithNamespace = | ||
'<note xmlns:h="http://www.w3.org/TR/html4/"><h:to>Tove</h:to><h:from>Jani</h:from></note>'; | ||
expect(isXml(validXmlWithNamespace)).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid XML string with self-closing tags', () => { | ||
const validXmlWithSelfClosingTags = | ||
'<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body/><footer/></note>'; | ||
expect(isXml(validXmlWithSelfClosingTags)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('Edge cases', () => { | ||
it('should return false for an empty string', () => { | ||
expect(isXml('')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with only whitespace', () => { | ||
expect(isXml(' ')).toBe(false); | ||
}); | ||
|
||
it('should return false for a string that is not XML', () => { | ||
const notXml = 'This is not an XML string'; | ||
expect(isXml(notXml)).toBe(false); | ||
}); | ||
|
||
it('should return false for a malformed XML string', () => { | ||
const malformedXml = | ||
"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body>"; | ||
expect(isXml(malformedXml)).toBe(false); | ||
}); | ||
|
||
it('should return false for a JSON string', () => { | ||
const jsonString = '{"name": "John", "age": 30, "city": "New York"}'; | ||
expect(isXml(jsonString)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with XML-like structure but invalid syntax', () => { | ||
const invalidXmlSyntax = | ||
"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body><note>"; | ||
expect(isXml(invalidXmlSyntax)).toBe(false); | ||
}); | ||
|
||
it('should return false for a string with special characters', () => { | ||
const specialChars = | ||
"<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!@#$%^&*()</body></note>"; | ||
expect(isXml(specialChars)).toBe(true); | ||
}); | ||
}); | ||
}); |
82 changes: 82 additions & 0 deletions
82
packages/utils/src/functions/string-util/test/prettifyJson.early.test.ts
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,82 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { prettifyJson } from '../index'; | ||
|
||
describe('prettifyJson() prettifyJson method', () => { | ||
describe('Happy Paths', () => { | ||
it('should prettify a valid JSON string', () => { | ||
const input = '{"name":"John","age":30,"city":"New York"}'; | ||
const expectedOutput = `{ | ||
"name": "John", | ||
"age": 30, | ||
"city": "New York" | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
|
||
it('should handle an already prettified JSON string', () => { | ||
const input = `{ | ||
"name": "John", | ||
"age": 30, | ||
"city": "New York" | ||
}`; | ||
const expectedOutput = `{ | ||
"name": "John", | ||
"age": 30, | ||
"city": "New York" | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
|
||
it('should handle a JSON string with arrays', () => { | ||
const input = '{"fruits":["apple","banana","cherry"]}'; | ||
const expectedOutput = `{ | ||
"fruits": [ | ||
"apple", | ||
"banana", | ||
"cherry" | ||
] | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
}); | ||
|
||
describe('Edge Cases', () => { | ||
it('should return the original string if it is not valid JSON', () => { | ||
const input = 'Invalid JSON string'; | ||
expect(prettifyJson(input)).toBe(input); | ||
}); | ||
|
||
it('should handle an empty string', () => { | ||
const input = ''; | ||
expect(prettifyJson(input)).toBe(input); | ||
}); | ||
|
||
it('should handle a JSON string with special characters', () => { | ||
const input = '{"special":"!@#$%^&*()_+{}|:\"<>?"}'; | ||
const expectedOutput = `{ | ||
"special": "!@#$%^&*()_+{}|:\\\"<>?" | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
|
||
it('should handle a JSON string with numbers and booleans', () => { | ||
const input = '{"number":123,"boolean":true}'; | ||
const expectedOutput = `{ | ||
"number": 123, | ||
"boolean": true | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
|
||
it('should handle a JSON string with nested objects', () => { | ||
const input = '{"person":{"name":"John","age":30}}'; | ||
const expectedOutput = `{ | ||
"person": { | ||
"name": "John", | ||
"age": 30 | ||
} | ||
}`; | ||
expect(prettifyJson(input)).toBe(expectedOutput); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.