UNPKG

@mytmpvpn/mytmpvpn-client

Version:

MyTmpVpn Client Library

47 lines (46 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const appconfig = require("../src/appconfig"); const common_1 = require("./common"); describe('Testing getVpn APIs', () => { var client; const appConfig = appconfig.loadDefaultAppConfig(); const userProfile = (0, common_1.createUserProfile)(); 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_REGION, 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.region, vpn.vpnId]) .toEqual([getVpn.vpn.config, getVpn.vpn.createdAt, getVpn.vpn.region, 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_REGION, 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.region, vpn.vpnId]) .toEqual([getVpn.vpn.config, getVpn.vpn.createdAt, getVpn.vpn.region, 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); }); });