Merge pull request #1637 from automatisch/rest-get-payment-plans
feat: Implement get payment plans API endpoint
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { renderObject } from '../../../../helpers/renderer.js';
|
||||
import Billing from '../../../../helpers/billing/index.ee.js';
|
||||
|
||||
export default async (request, response) => {
|
||||
const paymentPlans = Billing.paddlePlans;
|
||||
|
||||
renderObject(response, paymentPlans);
|
||||
};
|
@@ -0,0 +1,29 @@
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import app from '../../../../app.js';
|
||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
||||
import { createUser } from '../../../../../test/factories/user.js';
|
||||
import getPaymentPlansMock from '../../../../../test/mocks/rest/api/v1/payment/get-plans.js';
|
||||
import appConfig from '../../../../config/app.js';
|
||||
|
||||
describe('GET /api/v1/payment/plans', () => {
|
||||
let user, token;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await createUser();
|
||||
token = createAuthTokenByUserId(user.id);
|
||||
|
||||
vi.spyOn(appConfig, 'isCloud', 'get').mockReturnValue(true);
|
||||
});
|
||||
|
||||
it('should return payment plans', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/v1/payment/plans')
|
||||
.set('Authorization', token)
|
||||
.expect(200);
|
||||
|
||||
const expectedResponsePayload = await getPaymentPlansMock();
|
||||
|
||||
expect(response.body).toEqual(expectedResponsePayload);
|
||||
});
|
||||
});
|
10
packages/backend/src/routes/api/v1/payment.ee.js
Normal file
10
packages/backend/src/routes/api/v1/payment.ee.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Router } from 'express';
|
||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||
import checkIsCloud from '../../../helpers/check-is-cloud.js';
|
||||
import getPlansAction from '../../../controllers/api/v1/payment/get-plans.ee.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/plans', authenticateUser, checkIsCloud, getPlansAction);
|
||||
|
||||
export default router;
|
@@ -5,6 +5,7 @@ import paddleRouter from './paddle.ee.js';
|
||||
import healthcheckRouter from './healthcheck.js';
|
||||
import automatischRouter from './api/v1/automatisch.js';
|
||||
import usersRouter from './api/v1/users.js';
|
||||
import paymentRouter from './api/v1/payment.ee.js';
|
||||
import samlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
||||
import rolesRouter from './api/v1/admin/roles.ee.js';
|
||||
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
||||
@@ -17,6 +18,7 @@ router.use('/paddle', paddleRouter);
|
||||
router.use('/healthcheck', healthcheckRouter);
|
||||
router.use('/api/v1/automatisch', automatischRouter);
|
||||
router.use('/api/v1/users', usersRouter);
|
||||
router.use('/api/v1/payment', paymentRouter);
|
||||
router.use('/api/v1/admin/saml-auth-providers', samlAuthProvidersRouter);
|
||||
router.use('/api/v1/admin/roles', rolesRouter);
|
||||
router.use('/api/v1/admin/permissions', permissionsRouter);
|
||||
|
22
packages/backend/test/mocks/rest/api/v1/payment/get-plans.js
Normal file
22
packages/backend/test/mocks/rest/api/v1/payment/get-plans.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const getPaymentPlansMock = async () => {
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
limit: '10,000',
|
||||
name: '10k - monthly',
|
||||
price: '€20',
|
||||
productId: '47384',
|
||||
quota: 10000,
|
||||
},
|
||||
],
|
||||
meta: {
|
||||
count: 1,
|
||||
currentPage: null,
|
||||
isArray: true,
|
||||
totalPages: null,
|
||||
type: 'Object',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getPaymentPlansMock;
|
Reference in New Issue
Block a user