mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-03 05:06:34 +00:00
Adds test cases
This commit is contained in:
1 parent
cc5018eea4
commit
4cc037b048
2 files changed
+31
-20
No files matched your search
+28
-17
@@ -11,29 +11,41 @@ describe('Domains', () => {
|
||||
});
|
||||
|
||||
describe('validateDomainData', () => {
|
||||
it('should return true if the name is invalid', () => {
|
||||
const names = ['hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '', undefined, '12112**dsd', Array(101).fill('a').join('')];
|
||||
|
||||
names.forEach(name => {
|
||||
const { valid, errors } = validateDomainData({
|
||||
const invalidCases = [
|
||||
{},
|
||||
{ forceHttps: false },
|
||||
{ forceHttps: 1 },
|
||||
{ name: 'helo' },
|
||||
{ record: { CNAME: ['sd'] } },
|
||||
{ name: 'wwow', record: { A: ['12312'] } },
|
||||
...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')]
|
||||
.map(name => ({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
});
|
||||
})),
|
||||
];
|
||||
|
||||
const validCases = [
|
||||
{ name: 'asas', forceHttps: false, record: { A: ['111.111.111.111'] } },
|
||||
...['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'].map(name => ({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
}))
|
||||
];
|
||||
|
||||
it('should return false for invalid data', () => {
|
||||
invalidCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(false);
|
||||
expect(errors.length).toBe(1);
|
||||
expect(errors[0][0]).toBe('name');
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true for a valid object', () => {
|
||||
const names = ['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'];
|
||||
names.forEach(name => {
|
||||
const { valid, errors } = validateDomainData({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
});
|
||||
it('should return true if the name is valid', () => {
|
||||
validCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(true);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
@@ -44,7 +56,6 @@ describe('Domains', () => {
|
||||
it('should have a the correct keys', async () => {
|
||||
const list = await getDomains();
|
||||
list.forEach(data => {
|
||||
console.log(data);
|
||||
const { errors } = validateDomainData(data);
|
||||
if (errors.length) {
|
||||
console.log(errors);
|
||||
|
||||
Reference in new issue
Block a user