@@ -12,6 +12,7 @@ import {
1212 signUpAndGetSession ,
1313 testApi ,
1414} from "@/tests/unit/testUtils" ;
15+ import { DEFAULT_BRANDING } from "@/lib/branding" ;
1516
1617describe ( "GET /api/organizationConfig" , ( ) => {
1718 it ( "returns 200 and empty object when keys is []" , async ( ) => {
@@ -387,3 +388,79 @@ describe("PUT /api/organizationConfig", () => {
387388 expect ( data [ OrganizationConfigKey . DashboardLayout ] ) . toEqual ( layout ) ;
388389 } ) ;
389390} ) ;
391+
392+ describe ( "GET /api/organizationConfig branding" , ( ) => {
393+ it ( "returns documented defaults when no branding rows exist" , async ( ) => {
394+ await createOrganization ( "cfg-api-brand-default" ) ;
395+
396+ const response = await testApi . organizationConfig . $get ( {
397+ query : {
398+ keys : [ "primary_color" , "secondary_color" ] ,
399+ organizationSlug : "cfg-api-brand-default" ,
400+ } ,
401+ } ) ;
402+
403+ expect ( response . status ) . toBe ( 200 ) ;
404+ const data = await response . json ( ) ;
405+ expect ( data ) . toEqual ( {
406+ primary_color : DEFAULT_BRANDING [ OrganizationConfigKey . PrimaryColor ] ,
407+ secondary_color : DEFAULT_BRANDING [ OrganizationConfigKey . SecondaryColor ] ,
408+ } ) ;
409+ } ) ;
410+
411+ it ( "returns a configured primary color with the default secondary" , async ( ) => {
412+ const org = await createOrganization ( "cfg-api-brand-partial" ) ;
413+ await db . insert ( organizationConfig ) . values ( {
414+ id : randomUUID ( ) ,
415+ organizationId : org . id ,
416+ key : OrganizationConfigKey . PrimaryColor ,
417+ value : "#000000" ,
418+ } ) ;
419+
420+ const response = await testApi . organizationConfig . $get ( {
421+ query : {
422+ keys : [ "primary_color" , "secondary_color" ] ,
423+ organizationSlug : "cfg-api-brand-partial" ,
424+ } ,
425+ } ) ;
426+
427+ expect ( response . status ) . toBe ( 200 ) ;
428+ const data = await response . json ( ) ;
429+ expect ( data ) . toEqual ( {
430+ primary_color : "#000000" ,
431+ secondary_color : DEFAULT_BRANDING [ OrganizationConfigKey . SecondaryColor ] ,
432+ } ) ;
433+ } ) ;
434+
435+ it ( "does not override a fully configured organization" , async ( ) => {
436+ const org = await createOrganization ( "cfg-api-brand-full" ) ;
437+ await db . insert ( organizationConfig ) . values ( [
438+ {
439+ id : randomUUID ( ) ,
440+ organizationId : org . id ,
441+ key : OrganizationConfigKey . PrimaryColor ,
442+ value : "#123456" ,
443+ } ,
444+ {
445+ id : randomUUID ( ) ,
446+ organizationId : org . id ,
447+ key : OrganizationConfigKey . SecondaryColor ,
448+ value : "#654321" ,
449+ } ,
450+ ] ) ;
451+
452+ const response = await testApi . organizationConfig . $get ( {
453+ query : {
454+ keys : [ "primary_color" , "secondary_color" ] ,
455+ organizationSlug : "cfg-api-brand-full" ,
456+ } ,
457+ } ) ;
458+
459+ expect ( response . status ) . toBe ( 200 ) ;
460+ const data = await response . json ( ) ;
461+ expect ( data ) . toEqual ( {
462+ primary_color : "#123456" ,
463+ secondary_color : "#654321" ,
464+ } ) ;
465+ } ) ;
466+ } ) ;
0 commit comments