Skip to content

Commit

Permalink
Merge pull request #26 from snohio/lastlink/tests2
Browse files Browse the repository at this point in the history
add yaml jest type validations
  • Loading branch information
lastlink authored Mar 25, 2024
2 parents bb32713 + 3c6c66d commit 658944a
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Once packages are installed run the Netlfiy dev stack:
* http://localhost:8888/
* netlify cms http://localhost:8888/admin - needs to proxy to be run

## Run tests

* `npm run test`
* convert yaml to typescript using https://jsonformatter.org/yaml-to-typescript
---
## Live Demo

Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@11ty/eleventy-plugin-webc": "^0.11.2",
"@tailwindcss/typography": "^0.5.1",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/node-fetch": "^2.6.11",
"alpinejs": "^3.12.0",
"autoprefixer": "^10.4.2",
Expand Down
21 changes: 21 additions & 0 deletions tests/_data/board.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import BoardYamlInterfaceTI from "../types/Board.yaml-interface-ti";


describe('board.yaml', () => {
it('verify object', async () => {
const { BoardYaml } = createCheckers(BoardYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/board.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = BoardYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/events-yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import GroupEventInterfaceTI from "../types/GroupEvent-interface-ti";


describe('events.yml', () => {
it('verify object', () => {
const { EventYaml } = createCheckers(GroupEventInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/events.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = EventYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/groups.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import GroupsYamlInterfaceTI from "../types/Groups.yaml-interface-ti";


describe('groups.yaml', () => {
it('verify object', async () => {
const { GroupsYaml } = createCheckers(GroupsYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/groups.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = GroupsYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/navigation.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import NavigationYamlInterfaceTI from "../types/Navigation.yaml-interface-ti";


describe('navigation.yaml', () => {
it('verify object', async () => {
const { NavigationYaml } = createCheckers(NavigationYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/navigation.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = NavigationYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/quicklinks.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import QuicklinksYamlInterfaceTI from "../types/Quicklinks.yaml-interface-ti";


describe('quicklinks.yaml', () => {
it('verify object', async () => {
const { QuicklinksYaml } = createCheckers(QuicklinksYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/quicklinks.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = QuicklinksYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/settings.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import SettingsYamlInterfaceTI from "../types/Settings.yaml-interface-ti";


describe('settings.yaml', () => {
it('verify object', async () => {
const { SettingsYaml } = createCheckers(SettingsYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/settings.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = SettingsYaml.strictValidate(data);

expect(result).toBeNull();
});
})
21 changes: 21 additions & 0 deletions tests/_data/sponsors.yaml.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";
import fs from "fs";
import yaml from "js-yaml";

import {createCheckers} from "ts-interface-checker";
import SponsorsYamlInterfaceTI from "../types/Sponsors.yaml-interface-ti";


describe('sponsors.yaml', () => {
it('verify object', async () => {
const { SponsorsYaml } = createCheckers(SponsorsYamlInterfaceTI);

const filePath = path.join(__dirname, '../../src/_data/sponsors.yaml');
const fileContents = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(fileContents);

const result = SponsorsYaml.strictValidate(data);

expect(result).toBeNull();
});
})
20 changes: 20 additions & 0 deletions tests/types/Board.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface BoardYaml {
directors: Director[];
advisors: Advisor[];
former: Former[];
}

export interface Advisor {
name: string;
position: string;
}

export interface Director {
name: string;
role: string;
position: string;
}

export interface Former {
name: string;
}
4 changes: 4 additions & 0 deletions tests/types/GroupEvent-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ interface DevEvent {
priceInDollars: number;
}

interface EventYaml {
eventGroups: GroupEvent[];
}

interface GroupEvent {
host: string;
banner_img?: string;
Expand Down
8 changes: 8 additions & 0 deletions tests/types/Groups.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface GroupsYaml {
group: Group[];
}

export interface Group {
name: string;
description?: string;
}
8 changes: 8 additions & 0 deletions tests/types/Navigation.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface NavigationYaml {
items: Item[];
}

export interface Item {
text: string;
url?: string;
}
10 changes: 10 additions & 0 deletions tests/types/Quicklinks.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface QuicklinksYaml {
links: Link[];
}

export interface Link {
title: string;
url: string;
logo: string;
logo2?: string;
}
5 changes: 5 additions & 0 deletions tests/types/Settings.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface SettingsYaml {
name: string;
author: string;
url: string;
}
9 changes: 9 additions & 0 deletions tests/types/Sponsors.yaml-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface SponsorsYaml {
sponsors: Sponsor[];
}

export interface Sponsor {
name: string;
link: string;
img: string;
}

0 comments on commit 658944a

Please sign in to comment.