9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
import { createPageMock } from '../test-utils.js';
|
|
import './article.js';
|
|
|
|
describe('twitter article command', () => {
|
|
it('embeds tweet-id in page.evaluate through JSON.stringify', async () => {
|
|
const command = getRegistry().get('twitter/article');
|
|
const tweetId = '123"; window.__opencliInjected = true; //';
|
|
const page = createPageMock([
|
|
null,
|
|
[{
|
|
title: '(Note Tweet)',
|
|
author: 'alice',
|
|
content: 'hello',
|
|
url: 'https://x.com/alice/status/123',
|
|
}],
|
|
], {
|
|
getCookies: async () => [{ name: 'ct0', value: 'csrf-token' }],
|
|
});
|
|
|
|
const result = await command.func(page, { 'tweet-id': tweetId });
|
|
|
|
expect(result).toEqual([{
|
|
title: '(Note Tweet)',
|
|
author: 'alice',
|
|
content: 'hello',
|
|
url: 'https://x.com/alice/status/123',
|
|
}]);
|
|
expect(page.goto).toHaveBeenCalledWith(`https://x.com/i/status/${tweetId}`);
|
|
const graphqlScript = page.evaluate.mock.calls[1][0];
|
|
expect(graphqlScript).toContain(`const tweetId = ${JSON.stringify(tweetId)};`);
|
|
expect(graphqlScript).not.toContain('const tweetId = "123"; window.__opencliInjected = true; //";');
|
|
});
|
|
});
|