@applica-software-guru/persona-sdk 0.1.105 → 0.1.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+
4
+ import { ServicePricesApi } from '../dist/bundle.es.js';
5
+
6
+ function jsonResponse(body) {
7
+ return new Response(JSON.stringify(body), {
8
+ status: 200,
9
+ headers: { 'Content-Type': 'application/json' },
10
+ });
11
+ }
12
+
13
+ test('service price list forwards typed sort and filters', async (context) => {
14
+ const originalFetch = globalThis.fetch;
15
+ context.after(() => {
16
+ globalThis.fetch = originalFetch;
17
+ });
18
+
19
+ let requestUrl;
20
+ globalThis.fetch = async (url) => {
21
+ requestUrl = new URL(url);
22
+ return jsonResponse({ items: [], total: 0, page: 2, size: 10 });
23
+ };
24
+
25
+ const api = new ServicePricesApi('https://example.test', 'api-key');
26
+ await api.list('openai', 2, 10, {
27
+ sort: 'cost,desc',
28
+ unit: 'tokens',
29
+ pricingStatus: 'unpriced',
30
+ });
31
+
32
+ assert.equal(requestUrl.pathname, '/service-prices');
33
+ assert.deepEqual(Object.fromEntries(requestUrl.searchParams), {
34
+ page: '2',
35
+ size: '10',
36
+ sort: 'cost,desc',
37
+ unit: 'tokens',
38
+ pricingStatus: 'unpriced',
39
+ keyword: 'openai',
40
+ });
41
+ });
42
+
43
+ test('service price stats forwards its filters and returns KPI values', async (context) => {
44
+ const originalFetch = globalThis.fetch;
45
+ context.after(() => {
46
+ globalThis.fetch = originalFetch;
47
+ });
48
+
49
+ let requestUrl;
50
+ globalThis.fetch = async (url) => {
51
+ requestUrl = new URL(url);
52
+ return jsonResponse({ total: 10, priced: 7, unpriced: 3, withFixedPrice: 2 });
53
+ };
54
+
55
+ const api = new ServicePricesApi('https://example.test', 'api-key');
56
+ const stats = await api.getStats({ keyword: 'model', unit: 'tokens' });
57
+
58
+ assert.equal(requestUrl.pathname, '/service-prices/stats');
59
+ assert.deepEqual(Object.fromEntries(requestUrl.searchParams), {
60
+ keyword: 'model',
61
+ unit: 'tokens',
62
+ });
63
+ assert.deepEqual(stats, {
64
+ total: 10,
65
+ priced: 7,
66
+ unpriced: 3,
67
+ withFixedPrice: 2,
68
+ });
69
+ });