PHP Classes

File: tests/js/type-labels.test.js

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/js/type-labels.test.js   Download  
File: tests/js/type-labels.test.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Laravel Truss
View a diagram of a Laravel application models
Author: By
Last change:
Date: 9 days ago
Size: 1,903 bytes
 

Contents

Class file image Download
import { describe, it, expect } from 'vitest'; import { toShortLabel } from '../../resources/js/type-labels.js'; describe('toShortLabel ? best-effort native ? Laravel-style label', () => { it('maps integer family (incl. unsigned) to integer', () => { expect(toShortLabel('bigint unsigned')).toBe('integer'); expect(toShortLabel('int')).toBe('integer'); expect(toShortLabel('integer')).toBe('integer'); expect(toShortLabel('smallint')).toBe('integer'); expect(toShortLabel('mediumint')).toBe('integer'); }); it('maps tinyint(1) to boolean but wider tinyint to integer', () => { expect(toShortLabel('tinyint(1)')).toBe('boolean'); expect(toShortLabel('tinyint')).toBe('integer'); }); it('maps char/varchar families to string', () => { expect(toShortLabel('varchar(255)')).toBe('string'); expect(toShortLabel('char(36)')).toBe('string'); }); it('maps text families to text', () => { expect(toShortLabel('text')).toBe('text'); expect(toShortLabel('longtext')).toBe('text'); }); it('maps decimal/numeric to decimal and float/double to float', () => { expect(toShortLabel('decimal(8,2)')).toBe('decimal'); expect(toShortLabel('numeric(10,0)')).toBe('decimal'); expect(toShortLabel('double')).toBe('float'); expect(toShortLabel('float')).toBe('float'); }); it('maps temporal, boolean, json, uuid', () => { expect(toShortLabel('timestamp')).toBe('datetime'); expect(toShortLabel('datetime')).toBe('datetime'); expect(toShortLabel('date')).toBe('date'); expect(toShortLabel('boolean')).toBe('boolean'); expect(toShortLabel('json')).toBe('json'); expect(toShortLabel('uuid')).toBe('uuid'); }); it('falls back to the base token for anything unrecognized', () => { expect(toShortLabel('geometry')).toBe('geometry'); expect(toShortLabel('some_weird(1,2)')).toBe('some_weird'); }); });