Skip to content

Commit

Permalink
test: move getValue tests to express lib
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbutler committed Jan 22, 2023
1 parent 5d9ca79 commit e04f43f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
10 changes: 0 additions & 10 deletions libs/example-contracts/src/lib/contract-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ export interface PostTs {
const c = initContract();

export const contractTs = c.router({
test: {
testMethod: {
method: 'GET',
path: '/ts/posts',
responses: {
201: c.response<PostTs>(),
},
summary: 'Create a post',
},
},
createPost: {
method: 'POST',
path: '/ts/posts',
Expand Down
36 changes: 1 addition & 35 deletions libs/ts-rest/core/src/lib/type-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { z } from 'zod';
import { getValue, ZodInferOrType } from './type-utils';
import { ZodInferOrType } from './type-utils';

const zodObject = z.object({ title: z.string() });
type Test1 = ZodInferOrType<typeof zodObject>;
Expand All @@ -11,37 +11,3 @@ type Test2 = ZodInferOrType<typeof zodObject>;
type Test3 = ZodInferOrType<{ title: string }>;

it.todo('should infer type');

describe('getValue', () => {
it('should get one level deep', () => {
const obj = {
title: 'Title',
};

const value = getValue(obj, 'title');

expect(value).toBe('Title');
});

it('should get one level deep with nullable', () => {
const obj = {
title: 'Title',
};

const value = getValue(obj, 'test', null);

expect(value).toBe(null);
});

it('should get two levels deep', () => {
const obj = {
sub: {
text: 'text',
},
};

const value = getValue(obj, 'sub.text');

expect(value).toBe('text');
});
});
35 changes: 35 additions & 0 deletions libs/ts-rest/express/src/lib/ts-rest-express.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getValue } from './ts-rest-express';

describe('getValue', () => {
it('should get one level deep', () => {
const obj = {
title: 'Title',
};

const value = getValue(obj, 'title');

expect(value).toBe('Title');
});

it('should get one level deep with nullable', () => {
const obj = {
title: 'Title',
};

const value = getValue(obj, 'test', null);

expect(value).toBe(null);
});

it('should get two levels deep', () => {
const obj = {
sub: {
text: 'text',
},
};

const value = getValue(obj, 'sub.text');

expect(value).toBe('text');
});
});

0 comments on commit e04f43f

Please sign in to comment.