improved tests and typings

This commit is contained in:
Alex Duka
2018-12-05 00:50:04 +02:00
parent b5088e9b92
commit ce4d4743b7
2 changed files with 54 additions and 71 deletions
+48 -48
View File
@@ -4,69 +4,69 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace rabbitMqSchemaNc {
interface Binding {
destination: Topology;
source: Exchange;
args?: object;
routingPattern?: string;
}
interface Binding {
destination: Topology;
source: Exchange;
args?: object;
routingPattern?: string;
}
interface TopicBinding extends Binding {
routingPattern: string;
}
interface TopicBinding extends Binding {
routingPattern: string;
}
interface DirectBinding extends Binding {
routingPattern: string;
}
interface DirectBinding extends Binding {
routingPattern: string;
}
interface Topology {
options?: object;
}
interface Topology {
options?: object;
}
interface Exchange extends Topology {
exchange: string;
type: string;
bindings: Binding[];
}
interface Exchange extends Topology {
exchange: string;
type: string;
bindings: Binding[];
}
interface FanoutExchange extends Exchange {
type: 'fanout';
}
interface FanoutExchange extends Exchange {
type: 'fanout';
}
interface TopicExchange extends Exchange {
type: 'topic';
bindings: TopicBinding[];
}
interface TopicExchange extends Exchange {
type: 'topic';
bindings: TopicBinding[];
}
interface DirectExchange extends Exchange {
type: 'direct';
bindings: DirectBinding[];
}
interface DirectExchange extends Exchange {
type: 'direct';
bindings: DirectBinding[];
}
interface Queue extends Topology {
queue: string;
messageSchema: object;
}
interface Queue extends Topology {
queue: string;
messageSchema: object;
}
interface RabbitMQSchema {
new (schema: Topology | Topology[], parentPath?: string): RabbitMQSchema;
interface RabbitMQSchema {
new (schema: Topology | Topology[], parentPath?: string): RabbitMQSchema;
getExchanges(): Exchange[];
getBindings(): Binding[];
getQueues(): Queue[];
getDirectBindings(): DirectBinding[];
getExchanges(): Exchange[];
getBindings(): Binding[];
getQueues(): Queue[];
getDirectBindings(): DirectBinding[];
validate(schema: Topology | Topology[], parentPath?: string): void;
validateMessage<T>(exchangeName: string, routingPattern: string, message: T): T;
validate(schema: Topology | Topology[], parentPath?: string): void;
validateMessage<T>(exchangeName: string, routingPattern: string, message: T): T;
getQueueByName(name: string): Queue | void;
getExchangeByName(name: string): Exchange | void;
}
getQueueByName(name: string): Queue | void;
getExchangeByName(name: string): Exchange | void;
}
}
declare module 'rabbitmq-schema' {
const schema: rabbitMqSchemaNc.RabbitMQSchema;
export = schema;
const schema: rabbitMqSchemaNc.RabbitMQSchema;
export = schema;
}
+6 -23
View File
@@ -1,27 +1,10 @@
import RabbitMqSchema = require('rabbitmq-schema');
const topology: rabbitMqSchemaNc.Topology = {
const topology: rabbitMqSchemaNc.Exchange = {
exchange: 'images',
type: 'topic',
vhost: '/',
bindings: [
{
routingPattern: 'images.jpeg.get',
destination: {
queue: 'images.image.get',
messageSchema: {
type: 'object',
properties: {
testMsg: {
type: "string"
}
}
},
args: { 'message-ttl': 10000 }
}
}
]
}
bindings: []
};
const rabbitSchema = new RabbitMqSchema(topology, '');
@@ -30,8 +13,8 @@ const bindings: rabbitMqSchemaNc.Binding[] = rabbitSchema.getBindings();
const queues: rabbitMqSchemaNc.Queue[] = rabbitSchema.getQueues();
const directBindings: rabbitMqSchemaNc.DirectBinding[] = rabbitSchema.getDirectBindings();
const jpgQueue: rabbitMqSchemaNc.Queue = rabbitSchema.getQueueByName('images.jpeg.get');
const exchange: rabbitMqSchemaNc.Exchange = rabbitSchema.getExchangeByName('images');
const jpgQueue: rabbitMqSchemaNc.Queue | unknown = rabbitSchema.getQueueByName('images.jpeg.get');
const exchange: rabbitMqSchemaNc.Exchange | unknown = rabbitSchema.getExchangeByName('images');
rabbitSchema.validate(topology);
rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'});
rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'});