forked from asyncapi/parser-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add info and dependant models (asyncapi#485)
- Loading branch information
1 parent
81cc4ec
commit fbd4715
Showing
9 changed files
with
261 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import { BaseModel } from "./base"; | ||
import { Info } from "./info"; | ||
|
||
export class AsyncAPIDocument extends BaseModel {} | ||
export class AsyncAPIDocument extends BaseModel { | ||
version(): string { | ||
return this.json("asyncapi"); | ||
} | ||
|
||
info(): Info { | ||
return new Info(this.json("info")); | ||
} | ||
} |
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,15 @@ | ||
import { BaseModel } from "./base"; | ||
|
||
export class Contact extends BaseModel { | ||
name(): string { | ||
return this.json("name"); | ||
} | ||
|
||
url(): string { | ||
return this.json("url"); | ||
} | ||
|
||
email(): string { | ||
return this.json("email"); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from './asyncapi'; | ||
export * from './base'; | ||
export * from './contact'; | ||
export * from './info'; | ||
export * from './license'; |
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,31 @@ | ||
import { BaseModel } from "./base"; | ||
import { Contact } from "./contact"; | ||
import { License } from "./license"; | ||
|
||
export class Info extends BaseModel { | ||
title(): string { | ||
return this.json("title"); | ||
} | ||
|
||
version(): string { | ||
return this.json("version"); | ||
} | ||
|
||
description(): string { | ||
return this.json("description"); | ||
} | ||
|
||
termsOfService(): string { | ||
return this.json("termsOfService"); | ||
} | ||
|
||
contact(): Contact | undefined { | ||
const doc = this.json("contact"); | ||
return doc && new Contact(doc); | ||
} | ||
|
||
license(): License | undefined { | ||
const doc = this.json("license"); | ||
return doc && new License(doc); | ||
} | ||
} |
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,11 @@ | ||
import { BaseModel } from "./base"; | ||
|
||
export class License extends BaseModel { | ||
name(): string { | ||
return this.json("name"); | ||
} | ||
|
||
url(): string { | ||
return this.json("url"); | ||
} | ||
} |
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,26 @@ | ||
import { AsyncAPIDocument } from '../../src/models/asyncapi'; | ||
import { Info } from '../../src/models/info'; | ||
|
||
describe('AsyncAPIDocument model', function() { | ||
describe('.version()', function() { | ||
it('should return the value', function() { | ||
const doc = { asyncapi: "3.0.0" }; | ||
const d = new AsyncAPIDocument(doc); | ||
expect(d.version()).toEqual(doc.asyncapi); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new AsyncAPIDocument(doc); | ||
expect(d.version()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.info()', function() { | ||
it('should return an Info object', function() { | ||
const doc = { info: { name: "LeChuck" } }; | ||
const d = new AsyncAPIDocument(doc); | ||
expect(d.info() instanceof Info).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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,45 @@ | ||
import { Contact } from '../../src/models/contact'; | ||
|
||
describe('Contact model', function() { | ||
describe('.name()', function() { | ||
it('should return the value', function() { | ||
const doc = { name: "LeChuck" }; | ||
const d = new Contact(doc); | ||
expect(d.name()).toEqual(doc.name); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Contact(doc); | ||
expect(d.name()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.url()', function() { | ||
it('should return the value', function() { | ||
const doc = { url: "https://example.com" }; | ||
const d = new Contact(doc); | ||
expect(d.url()).toEqual(doc.url); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Contact(doc); | ||
expect(d.url()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.email()', function() { | ||
it('should return the value', function() { | ||
const doc = { email: "lechuck@example.com" }; | ||
const d = new Contact(doc); | ||
expect(d.email()).toEqual(doc.email); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Contact(doc); | ||
expect(d.email()).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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,89 @@ | ||
import { Contact } from '../../src/models/contact'; | ||
import { Info } from '../../src/models/info'; | ||
import { License } from '../../src/models/license'; | ||
|
||
describe('Info model', function() { | ||
describe('.title()', function() { | ||
it('should return the value', function() { | ||
const doc = { title: "Example API" }; | ||
const d = new Info(doc); | ||
expect(d.title()).toEqual(doc.title); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.title()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.version()', function() { | ||
it('should return the value', function() { | ||
const doc = { version: "1.0.0" }; | ||
const d = new Info(doc); | ||
expect(d.version()).toEqual(doc.version); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.version()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.description()', function() { | ||
it('should return the value', function() { | ||
const doc = { description: "This is the API of Example" }; | ||
const d = new Info(doc); | ||
expect(d.description()).toEqual(doc.description); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.description()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.termsOfService()', function() { | ||
it('should return the value', function() { | ||
const doc = { termsOfService: "These are the terms of service" }; | ||
const d = new Info(doc); | ||
expect(d.termsOfService()).toEqual(doc.termsOfService); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.termsOfService()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.contact()', function() { | ||
it('should return a Contact object', function() { | ||
const doc = { contact: { name: "LeChuck" } }; | ||
const d = new Info(doc); | ||
expect(d.contact() instanceof Contact).toBeTruthy(); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.contact()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.license()', function() { | ||
it('should return a License object', function() { | ||
const doc = { license: { name: "Apache 2.0" } }; | ||
const d = new Info(doc); | ||
expect(d.license() instanceof License).toBeTruthy(); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new Info(doc); | ||
expect(d.license()).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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,31 @@ | ||
import { License } from '../../src/models/license'; | ||
|
||
describe('License model', function() { | ||
describe('.name()', function() { | ||
it('should return the value', function() { | ||
const doc = { name: "Apache 2.0" }; | ||
const d = new License(doc); | ||
expect(d.name()).toEqual(doc.name); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new License(doc); | ||
expect(d.name()).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('.url()', function() { | ||
it('should return the value', function() { | ||
const doc = { url: "https://www.apache.org/licenses/LICENSE-2.0.html" }; | ||
const d = new License(doc); | ||
expect(d.url()).toEqual(doc.url); | ||
}); | ||
|
||
it('should return undefined when there is no value', function() { | ||
const doc = { }; | ||
const d = new License(doc); | ||
expect(d.url()).toBeUndefined(); | ||
}); | ||
}); | ||
}); |