UNPKG

@mytmpvpn/mytmpvpn-client

Version:

MyTmpVpn Client Library

71 lines (70 loc) 3.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const appconfig = __importStar(require("../src/appconfig")); const common_1 = require("./common"); const auth_1 = require("../src/auth"); describe('Testing getVpn APIs', () => { let client; const appConfig = appconfig.loadDefaultAppConfig(); const userProfile = (0, auth_1.createTestUserProfile)(); beforeAll(async () => { client = await (0, common_1.createAuthUser)(appConfig, userProfile); }, 600000); afterAll(async () => { await (0, common_1.deleteCleanUpAllAndDeleteAuthUser)(client, appConfig, userProfile); }, 600000); it("should return a vpn from a (userId, vpnId)", async () => { const vpnConfigLimits = await client.getVpnConfigLimits(); const vpnConfig = (0, common_1.getGoodPeanutsConfig)(vpnConfigLimits); const vpn = await client.createVpn(common_1.VPN_GEONAMES_ID, vpnConfig); expect(vpn).toBeDefined(); const getVpn = await client.getVpn(vpn.vpnId); // The returned vpn might have changed its state already, so they won't be deep equal. expect([vpn.config, vpn.createdAt, vpn.geonamesId, vpn.vpnId]) .toEqual([getVpn.vpn.config, getVpn.vpn.createdAt, getVpn.vpn.geonamesId, getVpn.vpn.vpnId]); await (0, common_1.cleanUp)(client, vpn); }); it("should return a vpn with the correct max config", async () => { const vpnConfigLimits = await client.getVpnConfigLimits(); const vpnConfig = (0, common_1.getMaxPeanutsConfig)(vpnConfigLimits); const vpn = await client.createVpn(common_1.VPN_GEONAMES_ID, vpnConfig); expect(vpn).toBeDefined(); const getVpn = await client.getVpn(vpn.vpnId); // The returned vpn might have changed its state already, so they won't be deep equal. expect([vpn.config, vpn.createdAt, vpn.geonamesId, vpn.vpnId]) .toEqual([getVpn.vpn.config, getVpn.vpn.createdAt, getVpn.vpn.geonamesId, getVpn.vpn.vpnId]); // Let's make sure the maxPeanuts remains '-1' all the way long. Rationale is to support // the following scenario: // T1: getBalance() == 20 - customer has 20 peanuts in their account // T2: createVpn(maxPeanuts=-1) == vpnId - customer creates a new VPN that is allowed to consume all peanuts in account // T3: getBalance() == 5 - peanuts have been consumed, customer buy new peanuts to avoid vpn auto-deletion // T4: getBalance() == 100 - new peanuts have been purchased // T5: getVpn(vpnId) -> the previous VPN should not have been deleted and should be allowed to consume // the new balance. That means the vpn.config.maxPeanuts should remain -1 expect(vpn.config.maxPeanuts).toEqual(-1); await (0, common_1.cleanUp)(client, vpn); }); });