From 828208aadb9b71a90a3e545f0c27728d1f81296e Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 15 Jul 2025 08:19:05 +1200 Subject: [PATCH] Add more ID validation test cases --- server/homebrew.api.spec.js | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 0b57588ea..0a6d1d452 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -128,7 +128,7 @@ describe('Tests for api', ()=>{ expect(googleId).toEqual('123456789012345678901234567890123'); }); - it('should throw invalid google id', ()=>{ + it('should throw invalid - google id right length but does not match pattern', ()=>{ let err; try { api.getId({ @@ -146,6 +146,42 @@ describe('Tests for api', ()=>{ expect(err).toEqual({ HBErrorCode: '12', brewId: 'abcdefghijkl', message: 'Invalid ID', name: 'Google ID Error', status: 404 }); }); + it('should throw invalid - google id too short (32 char)', ()=>{ + let err; + try { + api.getId({ + params : { + id : 'abcdefghijkl' + }, + body : { + googleId : '12345678901234567890123456789012' + } + }); + } catch (e) { + err = e; + } + + expect(err).toEqual({ HBErrorCode: '12', brewId: 'abcdefghijkl', message: 'Invalid ID', name: 'Google ID Error', status: 404 }); + }); + + it('should throw invalid - google id too long (45 char)', ()=>{ + let err; + try { + api.getId({ + params : { + id : 'abcdefghijkl' + }, + body : { + googleId : '123456789012345678901234567890123456789012345' + } + }); + } catch (e) { + err = e; + } + + expect(err).toEqual({ HBErrorCode: '12', brewId: 'abcdefghijkl', message: 'Invalid ID', name: 'Google ID Error', status: 404 }); + }); + it('should return 12-char id and google id from params', ()=>{ const { id, googleId } = api.getId({ params : {