Skip to content

Commit

Permalink
Merge pull request #3543 from elizaOS/tcm/fix-twitter-vitest
Browse files Browse the repository at this point in the history
fix: twitter vitest
  • Loading branch information
tcm390 authored Feb 17, 2025
2 parents e224ec7 + 9076a27 commit 48b9121
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 133 deletions.
18 changes: 11 additions & 7 deletions packages/plugin-twitter/__tests__/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,26 @@ describe('Twitter Client Base', () => {
TWITTER_RETRY_LIMIT: 5,
TWITTER_POLL_INTERVAL: 120,
TWITTER_ENABLE_POST_GENERATION: true,
POST_INTERVAL_MIN: 90,
POST_INTERVAL_MAX: 180,
TWITTER_POST_INTERVAL_MIN: 90,
TWITTER_POST_INTERVAL_MAX: 180,
TWITTER_POST_IMMEDIATELY: false
};
});

it('should create instance with correct configuration', () => {
const client = new ClientBase(mockRuntime);
const client = new ClientBase(mockRuntime, mockConfig);
expect(client).toBeDefined();
expect(mockRuntime.getSetting("TWITTER_USERNAME")).toBe('testuser');
expect(mockRuntime.getSetting("TWITTER_DRY_RUN")).toBe(true);
expect(client.state["TWITTER_USERNAME"]).toBe('testuser');
expect(mockRuntime.getSetting("TWITTER_DRY_RUN")).toBe('true');
expect(client.state["TWITTER_DRY_RUN"]).toBe(true);
});

it('should initialize with correct post intervals', () => {
const client = new ClientBase(mockRuntime);
expect(mockRuntime.getSetting("TWITTER_POST_INTERVAL_MIN")).toBe(90);
expect(mockRuntime.getSetting("TWITTER_POST_INTERVAL_MAX")).toBe(180);
const client = new ClientBase(mockRuntime, mockConfig);
expect(mockRuntime.getSetting("TWITTER_POST_INTERVAL_MIN")).toBe('90');
expect(client.state["TWITTER_POST_INTERVAL_MIN"]).toBe(90);
expect(mockRuntime.getSetting("TWITTER_POST_INTERVAL_MAX")).toBe('180');
expect(client.state["TWITTER_POST_INTERVAL_MAX"]).toBe(180);
});
});
46 changes: 24 additions & 22 deletions packages/plugin-twitter/__tests__/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import { describe, it, expect, vi } from 'vitest';
import { validateTwitterConfig } from '../src/environment';
import type { IAgentRuntime } from '@elizaos/core';

const env = {
TWITTER_USERNAME: 'testuser123',
TWITTER_DRY_RUN: 'true',
TWITTER_SPACES_ENABLE: 'false',
TWITTER_TARGET_USERS: 'user1,user2,user3',
TWITTER_POST_INTERVAL_MIN: '90',
TWITTER_POST_INTERVAL_MAX: '180',
TWITTER_ENABLE_ACTION_PROCESSING: 'false',
TWITTER_POST_IMMEDIATELY: 'false',
TWITTER_EMAIL: 'test@example.com',
TWITTER_PASSWORD: 'hashedpassword',
TWITTER_2FA_SECRET: '',
TWITTER_POLL_INTERVAL: '120',
TWITTER_RETRY_LIMIT: '5'
}

describe('Twitter Environment Configuration', () => {
const mockRuntime: IAgentRuntime = {
env: {
TWITTER_USERNAME: 'testuser123',
TWITTER_DRY_RUN: 'true',
TWITTER_SPACES_ENABLE: 'false',
TWITTER_TARGET_USERS: 'user1,user2,user3',
TWITTER_POST_INTERVAL_MIN: '90',
TWITTER_POST_INTERVAL_MAX: '180',
TWITTER_ENABLE_ACTION_PROCESSING: 'false',
TWITTER_POST_IMMEDIATELY: 'false',
TWITTER_EMAIL: 'test@example.com',
TWITTER_PASSWORD: 'hashedpassword',
TWITTER_2FA_SECRET: '',
TWITTER_POLL_INTERVAL: '120',
TWITTER_RETRY_LIMIT: '5'
},
env,
getEnv: function (key: string) {
return this.env[key] || null;
},
Expand All @@ -34,16 +36,16 @@ describe('Twitter Environment Configuration', () => {
expect(config.TWITTER_DRY_RUN).toBe(true);
expect(config.TWITTER_SPACES_ENABLE).toBe(false);
expect(config.TWITTER_TARGET_USERS).toEqual(['user1', 'user2', 'user3']);
expect(config.POST_INTERVAL_MIN).toBe(90);
expect(config.POST_INTERVAL_MAX).toBe(180);
expect(config.TWITTER_POST_INTERVAL_MIN).toBe(90);
expect(config.TWITTER_POST_INTERVAL_MAX).toBe(180);
expect(config.TWITTER_POST_IMMEDIATELY).toBe(false);
});

it('should validate wildcard username', async () => {
const wildcardRuntime = {
...mockRuntime,
env: {
...mockRuntime.env,
...env,
TWITTER_USERNAME: '*'
},
getEnv: function(key: string) {
Expand All @@ -62,7 +64,7 @@ describe('Twitter Environment Configuration', () => {
const validRuntime = {
...mockRuntime,
env: {
...mockRuntime.env,
...env,
TWITTER_USERNAME: 'test_user_123'
},
getEnv: function(key: string) {
Expand All @@ -81,7 +83,7 @@ describe('Twitter Environment Configuration', () => {
const runtimeWithoutTargets = {
...mockRuntime,
env: {
...mockRuntime.env,
...env,
TWITTER_TARGET_USERS: ''
},
getEnv: function(key: string) {
Expand Down Expand Up @@ -115,7 +117,7 @@ describe('Twitter Environment Configuration', () => {

const config = await validateTwitterConfig(minimalRuntime);
expect(config).toBeDefined();
expect(config.POST_INTERVAL_MIN).toBe(90);
expect(config.POST_INTERVAL_MAX).toBe(180);
expect(config.TWITTER_POST_INTERVAL_MIN).toBe(90);
expect(config.TWITTER_POST_INTERVAL_MAX).toBe(180);
});
});
Loading

0 comments on commit 48b9121

Please sign in to comment.