Skip to content

Commit

Permalink
Merge pull request #3 from Elhebert/ci/add-codecov
Browse files Browse the repository at this point in the history
ci: add codecov
  • Loading branch information
Elhebert authored Dec 19, 2023
2 parents ca2d717 + be874f0 commit e90f81c
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .asyncapi-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "AsyncAPI Validation",
"description": "Message validation package for YAML and JSON AsyncAPI documents.",
"links": {
"repoUrl": "https://github.com/Elhebert/asyncapi-validation"
},
"filters": {
"language": "TypeScript",
"technology": ["Node.js"],
"categories": ["validator"]
}
}
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ jobs:
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
coverage
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: ['./src/**'],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "asyncapi-validation",
"version": "0.1.1",
"description": "AsyncAPI message validation",
"description": "Message validation package for YAML and JSON AsyncAPI documents.",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
"files": [
Expand Down
40 changes: 40 additions & 0 deletions tests/from-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,44 @@ describe('parsing `fromFile`', () => {
expect((err as Error).message).toBe('data/lumens must be >= 0');
}
});

it('throw an error if the message key is not found for a 3.0.0 schema', async () => {
const validator = await asyncApiValidation.fromFile(
path.join(__dirname, 'fixtures', 'valid-schema-3.0.0.yaml')
);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});

it('throw an error if the message key is not found for a 2.0.0 schema', async () => {
const validator = await asyncApiValidation.fromFile(
path.join(__dirname, 'fixtures', 'valid-schema-2.0.0.yaml')
);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});
});
44 changes: 44 additions & 0 deletions tests/from-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,48 @@ describe('parsing `fromSchema`', () => {
expect((err as Error).message).toBe('data/lumens must be >= 0');
}
});

it('throw an error if the message key is not found for a 3.0.0 schema', async () => {
const schema = await readFile(
path.join(__dirname, 'fixtures', 'valid-schema-3.0.0.yaml'),
'utf-8'
);
const validator = await asyncApiValidation.fromSchema(schema);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});

it('throw an error if the message key is not found for a 2.0.0 schema', async () => {
const schema = await readFile(
path.join(__dirname, 'fixtures', 'valid-schema-2.0.0.yaml'),
'utf-8'
);
const validator = await asyncApiValidation.fromSchema(schema);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});
});
40 changes: 40 additions & 0 deletions tests/from-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,44 @@ describe('parsing `fromUrl`', () => {
expect((err as Error).message).toBe('data/lumens must be >= 0');
}
});

it('throw an error if the message key is not found for a 3.0.0 schema', async () => {
const validator = await asyncApiValidation.fromUrl(
'https://raw.githubusercontent.com/asyncapi/spec/v3.0.0/examples/streetlights-kafka-asyncapi.yml'
);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});

it('throw an error if the message key is not found for a 2.0.0 schema', async () => {
const validator = await asyncApiValidation.fromUrl(
'https://raw.githubusercontent.com/asyncapi/spec/v2.0.0/examples/2.0.0/streetlights.yml'
);

const payload = {
lumens: 10,
sendAt: '2020-08-06T15:00:00+00:00',
};

try {
validator('wrong-key', payload);
} catch (err) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toBe(
'No messages found for the given key'
);
}
});
});

0 comments on commit e90f81c

Please sign in to comment.