mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-11 01:36:16 +00:00
feat: Refactor and modularize flow handling for improved maintainability
- Extracted BuyModeHandler, DesktopFlow, MobileFlow, and SummaryReporter into separate modules for better organization and testability. - Enhanced type safety and added interfaces for various return types in Load, Logger, UserAgent, and flow modules. - Implemented comprehensive error handling and logging throughout the new modules. - Added unit tests for DesktopFlow, MobileFlow, and SummaryReporter to ensure functionality and correctness. - Updated existing utility functions to support new flow structures and improve code clarity.
This commit is contained in:
76
tests/flows/mobileFlow.test.ts
Normal file
76
tests/flows/mobileFlow.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
/**
|
||||
* MobileFlow unit tests
|
||||
* Validates mobile automation flow logic
|
||||
*/
|
||||
|
||||
test('MobileFlow module exports correctly', async () => {
|
||||
const { MobileFlow } = await import('../../src/flows/MobileFlow')
|
||||
assert.ok(MobileFlow, 'MobileFlow should be exported')
|
||||
assert.equal(typeof MobileFlow, 'function', 'MobileFlow should be a class constructor')
|
||||
})
|
||||
|
||||
test('MobileFlow has run method', async () => {
|
||||
const { MobileFlow } = await import('../../src/flows/MobileFlow')
|
||||
|
||||
// Mock bot instance
|
||||
const mockBot = {
|
||||
log: () => {},
|
||||
isMobile: true,
|
||||
config: {
|
||||
workers: {},
|
||||
runOnZeroPoints: false,
|
||||
searchSettings: { retryMobileSearchAmount: 0 }
|
||||
},
|
||||
browser: { func: {} },
|
||||
utils: {},
|
||||
activities: {},
|
||||
compromisedModeActive: false
|
||||
}
|
||||
|
||||
const flow = new MobileFlow(mockBot as never)
|
||||
assert.ok(flow, 'MobileFlow instance should be created')
|
||||
assert.equal(typeof flow.run, 'function', 'MobileFlow should have run() method')
|
||||
})
|
||||
|
||||
test('MobileFlowResult interface has correct structure', async () => {
|
||||
const { MobileFlow } = await import('../../src/flows/MobileFlow')
|
||||
|
||||
// Validate that MobileFlowResult type exports (compile-time check)
|
||||
type MobileFlowResult = Awaited<ReturnType<InstanceType<typeof MobileFlow>['run']>>
|
||||
|
||||
const mockResult: MobileFlowResult = {
|
||||
initialPoints: 1000,
|
||||
collectedPoints: 30
|
||||
}
|
||||
|
||||
assert.equal(typeof mockResult.initialPoints, 'number', 'initialPoints should be a number')
|
||||
assert.equal(typeof mockResult.collectedPoints, 'number', 'collectedPoints should be a number')
|
||||
})
|
||||
|
||||
test('MobileFlow accepts retry tracker', async () => {
|
||||
const { MobileFlow } = await import('../../src/flows/MobileFlow')
|
||||
const { MobileRetryTracker } = await import('../../src/util/MobileRetryTracker')
|
||||
|
||||
const mockBot = {
|
||||
log: () => {},
|
||||
isMobile: true,
|
||||
config: {
|
||||
workers: {},
|
||||
runOnZeroPoints: false,
|
||||
searchSettings: { retryMobileSearchAmount: 3 }
|
||||
},
|
||||
browser: { func: {} },
|
||||
utils: {},
|
||||
activities: {},
|
||||
compromisedModeActive: false
|
||||
}
|
||||
|
||||
const flow = new MobileFlow(mockBot as never)
|
||||
const tracker = new MobileRetryTracker(3)
|
||||
|
||||
assert.ok(flow, 'MobileFlow should accept retry tracker')
|
||||
assert.equal(typeof tracker.registerFailure, 'function', 'MobileRetryTracker should have registerFailure method')
|
||||
})
|
||||
Reference in New Issue
Block a user