11import { faker } from '@faker-js/faker' ;
2+ import { eq } from 'drizzle-orm' ;
23import { StatusCodes } from 'http-status-codes' ;
34import { v4 } from 'uuid' ;
45
@@ -13,6 +14,7 @@ import build, {
1314} from '../../../../../test/app' ;
1415import { seedFromJson } from '../../../../../test/mocks/seed' ;
1516import { db } from '../../../../drizzle/db' ;
17+ import { appsTable } from '../../../../drizzle/schema' ;
1618import type { AccountRaw , AppRaw , ItemWithCreator } from '../../../../drizzle/types' ;
1719import { assertIsDefined } from '../../../../utils/assertions' ;
1820import { APP_ITEMS_PREFIX } from '../../../../utils/config' ;
@@ -112,6 +114,27 @@ describe('Apps Plugin Tests', () => {
112114 } ) ;
113115 expect ( response . json ( ) . token ) . toBeTruthy ( ) ;
114116 } ) ;
117+
118+ it ( 'validation of payload' , async ( ) => {
119+ // remove apps that have been registered with this URL
120+ const url = 'http://localhost:3333' ;
121+ await db . delete ( appsTable ) . where ( eq ( appsTable . url , url ) ) ;
122+ const { apps } = await seedFromJson ( { apps : [ { url } ] } ) ;
123+ const chosenApp = apps [ 0 ] ;
124+ const {
125+ items : [ item ] ,
126+ } = await seedFromJson ( {
127+ items : [ { isPublic : true , type : ItemType . APP , extra : { app : { url : chosenApp . url } } } ] ,
128+ } ) ;
129+
130+ const response = await app . inject ( {
131+ method : HttpMethod . Post ,
132+ url : `${ APP_ITEMS_PREFIX } /${ item . id } /api-access-token` ,
133+ payload : { origin : chosenApp . url , key : chosenApp . key } ,
134+ } ) ;
135+ expect ( response . statusCode ) . toEqual ( StatusCodes . OK ) ;
136+ expect ( response . json ( ) . token ) . toBeTruthy ( ) ;
137+ } ) ;
115138 } ) ;
116139
117140 describe ( 'Signed In' , ( ) => {
0 commit comments