import { boolean , chain , Decoder , fields , fieldsAuto , number , string , } from "../" ; test ( "renaming fields" , ( ) => { type UserSnakeCase = { first_name : string ; last_name : string ; age : number ; active : boolean ; } ; const userSnakeCaseDecoder = fieldsAuto < UserSnakeCase > ( { first_name : string , last_name : string , age : number , active : boolean , } ) ; const user = { first_name : "John" , last_name : "Doe" , age : 30 , active : true , } ; expect ( userSnakeCaseDecoder ( user ) ) . toMatchInlineSnapshot ( `
    Object {
      "active": true,
      "age": 30,
      "first_name": "John",
      "last_name": "Doe",
    }
  ` ) ; type UserCamelCase = { firstName : string ; lastName : string ; age : number ; active : boolean ; } ; const userCamelCaseDecoder1 = fields ( ( field ) : UserCamelCase => ( { firstName : field ( "first_name" , string ) , lastName : field ( "last_name" , string ) , age : field ( "age" , number ) , active : field ( "active" , boolean ) , } ) ) ; expect ( userCamelCaseDecoder1 ( user ) ) . toMatchInlineSnapshot ( `
    Object {
      "active": true,
      "age": 30,
      "firstName": "John",
      "lastName": "Doe",
    }
  ` ) ; const userCamelCaseDecoder2 = chain ( userSnakeCaseDecoder , ( { first_name : firstName , last_name : lastName , ... rest } ) => ( { firstName , lastName , ... rest , } ) ) ; expect ( userCamelCaseDecoder2 ( user ) ) . toMatchInlineSnapshot ( `
    Object {
      "active": true,
      "age": 30,
      "firstName": "John",
      "lastName": "Doe",
    }
  ` ) ; const userCamelCaseDecoder3 = chain ( userSnakeCaseDecoder , ( props ) => ( { firstName : props . first_name , lastName : props . last_name , ... props , } ) ) ; expect ( userCamelCaseDecoder3 ( user ) ) . toMatchInlineSnapshot ( `
    Object {
      "active": true,
      "age": 30,
      "firstName": "John",
      "first_name": "John",
      "lastName": "Doe",
      "last_name": "Doe",
    }
  ` ) ; } ) ;