Skip to content

Commit c3c7beb

Browse files
committed
test: add unit tests for buildRequestBody and package exports
1 parent 18c447a commit c3c7beb

3 files changed

Lines changed: 30 additions & 237 deletions

File tree

lib/crux.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ afterEach(() => {
3636
});
3737

3838
// ─── Exports ─────────────────────────────────────────────────────────────────
39+
// ─── buildRequestBody ─────────────────────────────────────────────────────────
40+
41+
describe('buildRequestBody', () => {
42+
it('produces { url } for page scope with no form factor', () => {
43+
const body = buildRequestBody('https://example.com', 'page');
44+
expect(body).toEqual({ url: 'https://example.com' });
45+
});
46+
47+
it('produces { origin } for origin scope with no form factor', () => {
48+
const body = buildRequestBody('https://example.com/path', 'origin');
49+
expect(body).toEqual({ origin: 'https://example.com' });
50+
});
51+
52+
it('adds formFactor in uppercase when provided', () => {
53+
const phone = buildRequestBody('https://example.com', 'page', 'phone');
54+
expect(phone.formFactor).toBe('PHONE');
55+
56+
const desktop = buildRequestBody('https://example.com', 'page', 'desktop');
57+
expect(desktop.formFactor).toBe('DESKTOP');
58+
59+
const tablet = buildRequestBody('https://example.com', 'page', 'tablet');
60+
expect(tablet.formFactor).toBe('TABLET');
61+
});
62+
63+
it('omits formFactor from body when not provided', () => {
64+
const body = buildRequestBody('https://example.com', 'page');
65+
expect(Object.prototype.hasOwnProperty.call(body, 'formFactor')).toBe(false);
66+
});
67+
});
3968

4069
describe('exports', () => {
4170
it('buildRequestBody is exported', () => expect(typeof buildRequestBody).toBe('function'));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('package.json main field', () => {
99
});
1010

1111
describe('package root exports', () => {
12-
const lib = require('..');
12+
const lib = require('.');
1313

1414
it('exports runLabAudit', () => {
1515
expect(typeof lib.runLabAudit).toBe('function');

tests/crux.test.js

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)