@@ -3,6 +3,12 @@ import { describe, expect, it } from "@jest/globals";
33import { typeid , TypeID } from "../src/typeid" ;
44import validJson from "./valid" ;
55import invalidJson from "./invalid" ;
6+ import {
7+ InvalidPrefixError ,
8+ InvalidSuffixCharacterError ,
9+ InvalidSuffixLengthError ,
10+ PrefixMismatchError ,
11+ } from "../src/unboxed/error" ;
612
713describe ( "TypeID" , ( ) => {
814 describe ( "constructor" , ( ) => {
@@ -28,15 +34,11 @@ describe("TypeID", () => {
2834 it ( "should throw an error if prefix is not lowercase" , ( ) => {
2935 expect ( ( ) => {
3036 typeid ( "TEST" , "00041061050r3gg28a1c60t3gf" ) ;
31- } ) . toThrowError (
32- "Invalid prefix. Must be at most 63 ascii letters [a-z_]"
33- ) ;
37+ } ) . toThrowError ( new InvalidPrefixError ( "TEST" ) ) ;
3438
3539 expect ( ( ) => {
3640 typeid ( " " , "00041061050r3gg28a1c60t3gf" ) ;
37- } ) . toThrowError (
38- "Invalid prefix. Must be at most 63 ascii letters [a-z_]"
39- ) ;
41+ } ) . toThrowError ( new InvalidPrefixError ( " " ) ) ;
4042 } ) ;
4143
4244 it ( "should throw an error if suffix length is not 26" , ( ) => {
@@ -111,29 +113,25 @@ describe("TypeID", () => {
111113
112114 expect ( ( ) => {
113115 TypeID . fromString ( invalidStr ) ;
114- } ) . toThrowError (
115- new Error ( `Invalid suffix. First character must be in the range [0-7]` )
116- ) ;
116+ } ) . toThrowError ( new InvalidSuffixCharacterError ( "u" ) ) ;
117117 } ) ;
118118 it ( "should throw an error with wrong prefix" , ( ) => {
119119 const str = "prefix_00041061050r3gg28a1c60t3gf" ;
120120 expect ( ( ) => {
121121 TypeID . fromString ( str , "wrong" ) ;
122- } ) . toThrowError (
123- new Error ( `Invalid TypeId. Prefix mismatch. Expected wrong, got prefix` )
124- ) ;
122+ } ) . toThrowError ( new PrefixMismatchError ( "wrong" , "prefix" ) ) ;
125123 } ) ;
126124 it ( "should throw an error for empty TypeId string" , ( ) => {
127125 const invalidStr = "" ;
128126 expect ( ( ) => {
129127 TypeID . fromString ( invalidStr ) ;
130- } ) . toThrowError ( new Error ( `Invalid TypeId. Suffix cannot be empty` ) ) ;
128+ } ) . toThrowError ( new InvalidSuffixLengthError ( 0 ) ) ;
131129 } ) ;
132130 it ( "should throw an error for TypeId string with empty suffix" , ( ) => {
133131 const invalidStr = "prefix_" ;
134132 expect ( ( ) => {
135133 TypeID . fromString ( invalidStr ) ;
136- } ) . toThrowError ( new Error ( `Invalid TypeId. Suffix cannot be empty` ) ) ;
134+ } ) . toThrowError ( new InvalidSuffixLengthError ( 0 ) ) ;
137135 } ) ;
138136 } ) ;
139137
0 commit comments