Skip to content

Commit

Permalink
feat: more tests and scalar X extends ... support
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Dec 4, 2024
1 parent 8b94309 commit ffc6c3a
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ const convertScalar = (
return convertFloat(scalar, options)
case `string`:
return convertString(scalar, options)
default:
if (scalar.baseScalar) {
return convertScalar(scalar.baseScalar, options)
}
}

throw new Error(`Unhandled Scalar: ${scalar.name}`)
Expand Down
40 changes: 38 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,53 @@ beforeEach(async () => {
test.each([
{ name: `empty`, code: `` },
{
name: `empty-namespace`,
name: `file-namespace`,
code: `
namespace PetStore;
`,
},
{
name: `empty-model`,
name: `namespace`,
code: `
namespace PetStore {}
`,
},
{
name: `namespace-in-file-namespace`,
code: `
namespace PetStore;
namespace Pets {}
`,
},
{
name: `file-model`,
code: `
model Pet {}
`,
},
{
name: `model-in-namespace`,
code: `
namespace PetStore;
model Pet {}
`,
},
{
name: `model-and-namespace`,
code: `
namespace PetStore {}
model Pet {}
`,
},
{
name: `scalar`,
code: `
scalar Breed extends string;
`,
},
] satisfies { name: string; code: string }[])(
`$name`,
async ({ name, code }) => {
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions test/snapshots/model-and-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as fc from 'fast-check'

export const PetStore = {

};

export const Pet = fc.record({

});
7 changes: 7 additions & 0 deletions test/snapshots/model-in-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as fc from 'fast-check'

export const PetStore = {
Pet: fc.record({

}),
};
7 changes: 7 additions & 0 deletions test/snapshots/namespace-in-file-namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as fc from 'fast-check'

export const PetStore = {
Pets: {

},
};
5 changes: 5 additions & 0 deletions test/snapshots/namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as fc from 'fast-check'

export const PetStore = {

};
3 changes: 3 additions & 0 deletions test/snapshots/scalar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as fc from 'fast-check'

export const Breed = fc.string();

0 comments on commit ffc6c3a

Please sign in to comment.