yes-as-a-service-api-client 1.1.1 → 1.1.2
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.
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-

|
|
2
2
|

|
|
3
3
|

|
|
4
4
|

|
|
5
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
6
8
|
# Yes As A Service API Client
|
|
7
9
|
|
|
8
10
|
A tiny JavaScript/TypeScript client for the Yes As A Service API — fetch random positive affirmations with a single request.
|
|
@@ -84,6 +86,10 @@ All files | 100 | 100 | 100 | 100 |
|
|
|
84
86
|
Contributions, suggestions, and improvements are welcome.<br/>
|
|
85
87
|
Feel free to open issues or pull requests.
|
|
86
88
|
|
|
89
|
+
### 🔒 Security & Privacy
|
|
90
|
+
1. This package is open source and intended to provide reusable utilities for application development. It does not collect, store, transmit, sell, or share user data, and it does not include analytics, tracking, telemetry, cookies, local storage usage, backend services, or project-owned data collection mechanisms.
|
|
91
|
+
2. For more details, including vulnerability reporting guidance and consumer security recommendations, please see the [Security Policy](https://github.com/NPM-Workbench/vowelz/yes-as-a-service-api-client/policy).
|
|
92
|
+
|
|
87
93
|
### ❤️ Support
|
|
88
94
|
|
|
89
95
|
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "yes-as-a-service-api-client",
|
|
3
3
|
"description": "A minimal JavaScript/TypeScript client for the Yes As A Service API — an API that always responds with a positive affirmation.",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.2",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/get-a-yes/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
import { getAYes } from './index.js';
|
|
3
|
-
/* mock console.error to keep test output clean */
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
6
|
-
});
|
|
7
|
-
/* restore mocks after each test */
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
jest.restoreAllMocks();
|
|
10
|
-
});
|
|
11
|
-
describe('getAYes', () => {
|
|
12
|
-
/* #1 */
|
|
13
|
-
it('returns api-ok and payload when fetch resolves with ok=true', async () => {
|
|
14
|
-
const mockAff = 'Yes, you can!';
|
|
15
|
-
const mockResponse = {
|
|
16
|
-
ok: true,
|
|
17
|
-
json: jest.fn().mockResolvedValue({ reason: mockAff }),
|
|
18
|
-
};
|
|
19
|
-
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
20
|
-
const res = await getAYes();
|
|
21
|
-
expect(res.code).toBe('api-ok');
|
|
22
|
-
});
|
|
23
|
-
/* #2 */
|
|
24
|
-
it('returns api-fail when response.ok is false', async () => {
|
|
25
|
-
global.fetch = jest.fn().mockResolvedValue({ ok: false });
|
|
26
|
-
const res = await getAYes();
|
|
27
|
-
expect(res.code).toBe('api-fail');
|
|
28
|
-
});
|
|
29
|
-
/* #3 */
|
|
30
|
-
it('returns api-fail when fetch throws', async () => {
|
|
31
|
-
global.fetch = jest.fn().mockRejectedValue(new Error('network'));
|
|
32
|
-
const res = await getAYes();
|
|
33
|
-
expect(res.code).toBe('api-fail');
|
|
34
|
-
});
|
|
35
|
-
/* #4 */
|
|
36
|
-
it('returns api-fail when json parsing fails', async () => {
|
|
37
|
-
const mockResponse = {
|
|
38
|
-
ok: true,
|
|
39
|
-
json: jest.fn().mockRejectedValue(new Error('invalid json')),
|
|
40
|
-
};
|
|
41
|
-
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
42
|
-
const res = await getAYes();
|
|
43
|
-
expect(res.code).toBe('api-fail');
|
|
44
|
-
});
|
|
45
|
-
/* #5 */
|
|
46
|
-
it('returns object payload with affirmation on success (payload test)', async () => {
|
|
47
|
-
const mockAff = 'Affirmative payload check';
|
|
48
|
-
const mockResponse = {
|
|
49
|
-
ok: true,
|
|
50
|
-
json: jest.fn().mockResolvedValue({ reason: mockAff }),
|
|
51
|
-
};
|
|
52
|
-
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
53
|
-
const res = await getAYes();
|
|
54
|
-
expect(res.payload).not.toBeNull();
|
|
55
|
-
expect(res.payload?.affirmation).toBe(mockAff);
|
|
56
|
-
});
|
|
57
|
-
/* #6 */
|
|
58
|
-
it('returns null payload on fetch error (payload null test)', async () => {
|
|
59
|
-
global.fetch = jest.fn().mockRejectedValue(new Error('network'));
|
|
60
|
-
const res = await getAYes();
|
|
61
|
-
expect(res.payload).toBeNull();
|
|
62
|
-
expect(res.code).toBe('api-fail');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/get-a-yes/index.test.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,kDAAkD;AAClD,UAAU,CAAC,GAAG,EAAE;IACd,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAEH,mCAAmC;AACnC,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,eAAe,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,QAAQ;IACR,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,OAAO,G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