Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { expect, test } from 'vitest'; |
| 2 | |
| 3 | import { genericParameter } from './GenericParameter'; |
| 4 | import { interfaceDeclaration } from './Interface'; |
| 5 | import { method } from './Method'; |
| 6 | import { namedType } from './NamedType'; |
| 7 | import { property } from './Property'; |
| 8 | import { stringify } from './stringify'; |
| 9 | |
| 10 | const A = namedType('A'); |
| 11 | |
| 12 | test('empty', () => { |
| 13 | const obj = interfaceDeclaration('MyInterface'); |
| 14 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 15 | "interface MyInterface {} |
| 16 | " |
| 17 | `); |
| 18 | }); |
| 19 | |
| 20 | test('with property', () => { |
| 21 | const obj = interfaceDeclaration('SomeInterface').add(property('foo', A)); |
| 22 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 23 | "interface SomeInterface { |
| 24 | foo: A |
| 25 | }" |
| 26 | `); |
| 27 | }); |
| 28 | |
| 29 | test('with method', () => { |
| 30 | const obj = interfaceDeclaration('MyInterface').add(method('doThing')); |
| 31 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 32 | "interface MyInterface { |
| 33 | doThing(): void |
| 34 | }" |
| 35 | `); |
| 36 | }); |
| 37 | |
| 38 | test('with generic parameter', () => { |
| 39 | const obj = interfaceDeclaration('SomeInterface') |
| 40 | .addGenericParameter(genericParameter('T').extends(namedType('U'))) |
| 41 | .add(property('foo', A)); |
| 42 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 43 | "interface SomeInterface<T extends U> { |
| 44 | foo: A |
| 45 | }" |
| 46 | `); |
| 47 | }); |
| 48 | |
| 49 | test('extending the type', () => { |
| 50 | const obj = interfaceDeclaration('SomeInterface') |
| 51 | .extends(namedType('Foo')) |
| 52 | .add(property('foo', A)); |
| 53 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 54 | "interface SomeInterface extends Foo { |
| 55 | foo: A |
| 56 | }" |
| 57 | `); |
| 58 | }); |
| 59 | |
| 60 | test('extending multiple types', () => { |
| 61 | const obj = interfaceDeclaration('SomeInterface') |
| 62 | .extends(namedType('Foo')) |
| 63 | .extends(namedType('Bar')) |
| 64 | .add(property('foo', A)); |
| 65 | expect(stringify(obj)).toMatchInlineSnapshot(` |
| 66 | "interface SomeInterface extends Foo, Bar { |
| 67 | foo: A |
| 68 | }" |
| 69 | `); |
| 70 | }); |