feat: add 5SIM provider
This commit is contained in:
+101
-1
@@ -25,7 +25,7 @@ function load(extra = {}) {
|
||||
Set,
|
||||
...extra,
|
||||
};
|
||||
const fn = new Function('globalThis', 'self', `with (globalThis) { ${source}; return { collectPriceEntries, filterPriceEntries, normalizeActivation, extractVerificationCode, isPhoneNumberUsedError, isPhoneNumberDeliveryRefusedError, getPhoneReplacementReleaseAction, fetchNextPhone, normalizeSettings, buildUrl, fetchActiveCode }; }`);
|
||||
const fn = new Function('globalThis', 'self', `with (globalThis) { ${source}; return { collectPriceEntries, filterPriceEntries, normalizeActivation, extractVerificationCode, isPhoneNumberUsedError, isPhoneNumberDeliveryRefusedError, getPhoneReplacementReleaseAction, fetchNextPhone, normalizeSettings, buildUrl, fetchActiveCode, releaseActivation }; }`);
|
||||
return fn(sandbox, sandbox);
|
||||
}
|
||||
test('collectPriceEntries parses keyed price inventory', () => {
|
||||
@@ -202,3 +202,103 @@ test('fetchActiveCode parses Luban success SMS code', async () => {
|
||||
assert.equal(result.code, '380682');
|
||||
assert.equal(stored.activeActivation.lastCode, '380682');
|
||||
});
|
||||
|
||||
|
||||
test('buildUrl uses 5SIM bearer-token style URL without api_key query', () => {
|
||||
const api = load();
|
||||
const url = new URL(api.buildUrl(
|
||||
{ provider: '5sim', fiveSimBaseUrl: 'https://5sim.net', apiKey: 'five-token' },
|
||||
{ __path: 'v1/user/buy/activation/vietnam/any/openai', maxPrice: 0.2 }
|
||||
));
|
||||
assert.equal(url.origin, 'https://5sim.net');
|
||||
assert.equal(url.pathname, '/v1/user/buy/activation/vietnam/any/openai');
|
||||
assert.equal(url.searchParams.get('api_key'), null);
|
||||
assert.equal(url.searchParams.get('apikey'), null);
|
||||
assert.equal(url.searchParams.get('maxPrice'), '0.2');
|
||||
});
|
||||
|
||||
test('fetchNextPhone acquires 5SIM number with Authorization bearer token', async () => {
|
||||
const requests = [];
|
||||
const stored = {
|
||||
provider: '5sim',
|
||||
apiKey: 'five-token',
|
||||
fiveSimBaseUrl: 'https://5sim.net',
|
||||
fiveSimCountry: 'vietnam',
|
||||
fiveSimOperator: 'any',
|
||||
fiveSimProduct: 'openai',
|
||||
maxPrice: '0.25',
|
||||
};
|
||||
const api = load({
|
||||
chrome: {
|
||||
action: { onClicked: { addListener() {} } },
|
||||
tabs: { async sendMessage() {} },
|
||||
scripting: { async executeScript() {} },
|
||||
runtime: { onMessage: { addListener() {} } },
|
||||
storage: { local: { async get() { return stored; }, async set(update) { Object.assign(stored, update); } } }
|
||||
},
|
||||
fetch: async (url, options = {}) => {
|
||||
const parsed = new URL(url);
|
||||
requests.push([parsed.pathname, parsed.searchParams.get('maxPrice'), options.headers.Authorization]);
|
||||
if (parsed.pathname === '/v1/user/buy/activation/vietnam/any/openai') {
|
||||
return new Response(JSON.stringify({ id: 11631253, phone: '+84901234567', operator: 'viettel', product: 'openai', price: 0.2, status: 'PENDING', country: 'vietnam' }), { status: 200 });
|
||||
}
|
||||
throw new Error(`unexpected ${url}`);
|
||||
},
|
||||
Response,
|
||||
});
|
||||
const result = await api.fetchNextPhone({ reason: 'manual_replace', releaseAction: 'cancel' });
|
||||
assert.equal(result.activation.provider, '5sim');
|
||||
assert.equal(result.activation.activationId, '11631253');
|
||||
assert.equal(result.activation.phoneNumber, '+84901234567');
|
||||
assert.equal(stored.activeActivation.activationId, '11631253');
|
||||
assert.deepEqual(requests, [['/v1/user/buy/activation/vietnam/any/openai', '0.25', 'Bearer five-token']]);
|
||||
});
|
||||
|
||||
test('fetchActiveCode parses 5SIM order SMS code', async () => {
|
||||
const stored = {
|
||||
provider: '5sim',
|
||||
apiKey: 'five-token',
|
||||
fiveSimBaseUrl: 'https://5sim.net',
|
||||
activeActivation: { activationId: '11631253', phoneNumber: '+84901234567', provider: '5sim' },
|
||||
};
|
||||
const api = load({
|
||||
chrome: {
|
||||
action: { onClicked: { addListener() {} } },
|
||||
tabs: { async sendMessage() {} },
|
||||
scripting: { async executeScript() {} },
|
||||
runtime: { onMessage: { addListener() {} } },
|
||||
storage: { local: { async get() { return stored; }, async set(update) { Object.assign(stored, update); } } }
|
||||
},
|
||||
fetch: async (url, options = {}) => {
|
||||
const parsed = new URL(url);
|
||||
assert.equal(parsed.pathname, '/v1/user/check/11631253');
|
||||
assert.equal(options.headers.Authorization, 'Bearer five-token');
|
||||
return new Response(JSON.stringify({ id: 11631253, status: 'RECEIVED', sms: [{ text: 'Your code is 09363', code: '09363' }] }), { status: 200 });
|
||||
},
|
||||
Response,
|
||||
});
|
||||
const result = await api.fetchActiveCode();
|
||||
assert.equal(result.code, '09363');
|
||||
assert.equal(stored.activeActivation.lastCode, '09363');
|
||||
});
|
||||
|
||||
test('releaseActivation cancels or bans 5SIM order using management endpoints', async () => {
|
||||
const requests = [];
|
||||
const stored = { provider: '5sim', apiKey: 'five-token', fiveSimBaseUrl: 'https://5sim.net' };
|
||||
const api = load({
|
||||
fetch: async (url, options = {}) => {
|
||||
const parsed = new URL(url);
|
||||
requests.push([parsed.pathname, options.headers.Authorization]);
|
||||
return new Response(JSON.stringify({ id: 1001, status: parsed.pathname.includes('/ban/') ? 'BANNED' : 'CANCELED' }), { status: 200 });
|
||||
},
|
||||
Response,
|
||||
});
|
||||
const cancel = await api.releaseActivation(stored, { activationId: '1001' }, 'cancel');
|
||||
const ban = await api.releaseActivation(stored, { activationId: '1002' }, 'ban');
|
||||
assert.equal(cancel.ok, true);
|
||||
assert.equal(ban.ok, true);
|
||||
assert.deepEqual(requests, [
|
||||
['/v1/user/cancel/1001', 'Bearer five-token'],
|
||||
['/v1/user/ban/1002', 'Bearer five-token'],
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user