Skip to content

Commit f29f969

Browse files
committed
fix: add test for app origin url format
1 parent a69948d commit f29f969

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Environment = {
77
test: 'test',
88
} as const;
99

10-
export const NODE_ENV: string | undefined = process.env.NODE_ENV;
10+
export const NODE_ENV = process.env.NODE_ENV ?? Environment.development;
1111

1212
const once = (fn) => {
1313
let called = false;

src/services/item/plugins/app/app.controller.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { faker } from '@faker-js/faker';
2+
import { eq } from 'drizzle-orm';
23
import { StatusCodes } from 'http-status-codes';
34
import { v4 } from 'uuid';
45

@@ -13,6 +14,7 @@ import build, {
1314
} from '../../../../../test/app';
1415
import { seedFromJson } from '../../../../../test/mocks/seed';
1516
import { db } from '../../../../drizzle/db';
17+
import { appsTable } from '../../../../drizzle/schema';
1618
import type { AccountRaw, AppRaw, ItemWithCreator } from '../../../../drizzle/types';
1719
import { assertIsDefined } from '../../../../utils/assertions';
1820
import { 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', () => {

src/services/item/plugins/app/app.schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const generateToken = {
2020
}),
2121
body: customType.StrictObject({
2222
key: customType.UUID(),
23-
origin: Type.String({ format: 'url' }),
23+
origin: Type.String({ format: 'url' }), // should be `uri` for http://localhost:3333 to be valid
2424
}),
2525
response: {
2626
[StatusCodes.OK]: Type.Object({ token: Type.String() }),

0 commit comments

Comments
 (0)