Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

add simple payment tests

Fendy Heryanto93b8db8f8af8
diff --git a/packages/nocodb/tests/unit/rest/index.test.ts b/packages/nocodb/tests/unit/rest/index.test.ts
index 3b38585915..f0bca67fde 100644
--- a/packages/nocodb/tests/unit/rest/index.test.ts
+++ b/packages/nocodb/tests/unit/rest/index.test.ts
@@ -16,6 +16,7 @@ import aggregationTest from './tests/aggregation.test';
import dataAPIsV3Test from './tests/dataAPIsV3.test';
import metaTestV3 from './tests/metaApiV3/index.test';
import tableTests from './tests/meta-apis/table.test';
+import { paymentTest } from './tests/payment/payment.test';
let workspaceTest = () => {};
let ssoTest = () => {};
@@ -54,6 +55,7 @@ function restTests() {
bulkAggregationTest();
columnTest();
integrationTest();
+ paymentTest();
if (testVersion.includes('v1')) tableTests('v1');
if (testVersion.includes('v2')) dataAPIsV3Test('v2');
diff --git a/packages/nocodb/tests/unit/rest/tests/payment/beforeEach.ts b/packages/nocodb/tests/unit/rest/tests/payment/beforeEach.ts
new file mode 100644
index 0000000000..19fba3a746
--- /dev/null
+++ b/packages/nocodb/tests/unit/rest/tests/payment/beforeEach.ts
@@ -0,0 +1,19 @@
+import { createProject } from '../../../factory/base';
+import init from '../../../init';
+import type { ITestContext } from './helpers';
+
+export const beforeEach = async () => {
+ const context = await init();
+ const base = await createProject(context);
+
+ const ctx = {
+ workspace_id: base.fk_workspace_id!,
+ base_id: base.id,
+ };
+
+ return {
+ context,
+ ctx,
+ base,
+ } as ITestContext;
+};
diff --git a/packages/nocodb/tests/unit/rest/tests/payment/helpers.ts b/packages/nocodb/tests/unit/rest/tests/payment/helpers.ts
new file mode 100644
index 0000000000..c98d38bf10
--- /dev/null
+++ b/packages/nocodb/tests/unit/rest/tests/payment/helpers.ts
@@ -0,0 +1,11 @@
+import type { Base } from '../../../../../src/models';
+import type init from '../../../init';
+
+export interface ITestContext {
+ context: Awaited<ReturnType<typeof init>>;
+ ctx: {
+ workspace_id: any;
+ base_id: any;
+ };
+ base: Base;
+}
diff --git a/packages/nocodb/tests/unit/rest/tests/payment/payment.test.ts b/packages/nocodb/tests/unit/rest/tests/payment/payment.test.ts
new file mode 100644
index 0000000000..57fa22df27
--- /dev/null
+++ b/packages/nocodb/tests/unit/rest/tests/payment/payment.test.ts
@@ -0,0 +1,48 @@
+import { expect } from 'chai';
+import { type INcAxios, ncAxios } from '../dataApiV3/ncAxios';
+import { beforeEach as initBeforeEach } from './beforeEach';
+import type { ITestContext } from './helpers';
+
+export function paymentTest() {
+ describe(`Payment`, () => {
+ let testContext: ITestContext;
+ let testAxios: INcAxios;
+ let ncAxiosGet: INcAxios['ncAxiosGet'];
+ let ncAxiosPost: INcAxios['ncAxiosPost'];
+ let ncAxiosPatch: INcAxios['ncAxiosPatch'];
+ let ncAxiosDelete: INcAxios['ncAxiosDelete'];
+ let ncAxiosLinkGet: INcAxios['ncAxiosLinkGet'];
+ let ncAxiosLinkAdd: INcAxios['ncAxiosLinkAdd'];
+ let ncAxiosLinkRemove: INcAxios['ncAxiosLinkRemove'];
+
+ beforeEach(async () => {
+ testContext = await initBeforeEach();
+ testAxios = ncAxios(testContext);
+
+ ncAxiosGet = testAxios.ncAxiosGet;
+ ncAxiosPost = testAxios.ncAxiosPost;
+ ncAxiosPatch = testAxios.ncAxiosPatch;
+ ncAxiosDelete = testAxios.ncAxiosDelete;
+ ncAxiosLinkGet = testAxios.ncAxiosLinkGet;
+ ncAxiosLinkAdd = testAxios.ncAxiosLinkAdd;
+ ncAxiosLinkRemove = testAxios.ncAxiosLinkRemove;
+ });
+
+ it(`will get public plans`, async () => {
+ const result = await ncAxiosGet({
+ url: '/api/public/payment/plan',
+ });
+ expect(Array.isArray(result.body)).to.eq(true);
+ });
+ it(`will get workspace invoices without subscription`, async () => {
+ const result = await ncAxiosGet({
+ url: `/api/payment/${testContext.ctx.workspace_id}/invoice`,
+ status: 404,
+ });
+ expect(result.body.error).to.eq('GENERIC_NOT_FOUND');
+ expect(result.body.message).to.eq(
+ `Subscription '${testContext.ctx.workspace_id}' not found`,
+ );
+ });
+ });
+}