@@ -75,6 +75,7 @@ import {
7575 IsISO31661Alpha2 ,
7676 IsISO31661Alpha3 ,
7777 IsHash ,
78+ IsMACAddress ,
7879 IsISSN ,
7980} from "../../src/decorator/decorators" ;
8081import { Validator } from "../../src/validation/Validator" ;
@@ -2025,6 +2026,55 @@ describe("IsHexadecimal", function() {
20252026
20262027} ) ;
20272028
2029+ describe ( "IsMACAddress" , function ( ) {
2030+
2031+ const validValues = [
2032+ "ab:ab:ab:ab:ab:ab" ,
2033+ "FF:FF:FF:FF:FF:FF" ,
2034+ "01:02:03:04:05:ab" ,
2035+ "01:AB:03:04:05:06"
2036+ ] ;
2037+ const invalidValues = [
2038+ null ,
2039+ undefined ,
2040+ "abc" ,
2041+ "01:02:03:04:05" ,
2042+ "01:02:03:04::ab" ,
2043+ "1:2:3:4:5:6" ,
2044+ "AB:CD:EF:GH:01:02" ,
2045+ "A9C5 D4 9F EB D3" ,
2046+ "01-02 03:04 05 ab" ,
2047+ ] ;
2048+
2049+ class MyClass {
2050+ @IsMACAddress ( )
2051+ someProperty : string ;
2052+ }
2053+
2054+ it ( "should not fail if validator.validate said that its valid" , function ( done ) {
2055+ checkValidValues ( new MyClass ( ) , validValues , done ) ;
2056+ } ) ;
2057+
2058+ it ( "should fail if validator.validate said that its invalid" , function ( done ) {
2059+ checkInvalidValues ( new MyClass ( ) , invalidValues , done ) ;
2060+ } ) ;
2061+
2062+ it ( "should not fail if method in validator said that its valid" , function ( ) {
2063+ validValues . forEach ( value => validator . isMACAddress ( value ) . should . be . true ) ;
2064+ } ) ;
2065+
2066+ it ( "should fail if method in validator said that its invalid" , function ( ) {
2067+ invalidValues . forEach ( value => validator . isMACAddress ( value ) . should . be . false ) ;
2068+ } ) ;
2069+
2070+ it ( "should return error object with proper data" , function ( done ) {
2071+ const validationType = "isMacAddress" ;
2072+ const message = "someProperty must be a MAC Address" ;
2073+ checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message , done ) ;
2074+ } ) ;
2075+
2076+ } ) ;
2077+
20282078describe ( "IsIP" , function ( ) {
20292079
20302080 const validValues = [
0 commit comments