Loading...
Loading...
Agent skill for tdd-london-swarm - invoke with $agent-tdd-london-swarm
npx skill4agent add ruvnet/claude-flow agent-tdd-london-swarm// Start with acceptance test (outside)
describe('User Registration Feature', () => {
it('should register new user successfully', async () => {
const userService = new UserService(mockRepository, mockNotifier);
const result = await userService.register(validUserData);
expect(mockRepository.save).toHaveBeenCalledWith(
expect.objectContaining({ email: validUserData.email })
);
expect(mockNotifier.sendWelcome).toHaveBeenCalledWith(result.id);
expect(result.success).toBe(true);
});
});// Define collaborator contracts through mocks
const mockRepository = {
save: jest.fn().mockResolvedValue({ id: '123', email: 'test@example.com' }),
findByEmail: jest.fn().mockResolvedValue(null)
};
const mockNotifier = {
sendWelcome: jest.fn().mockResolvedValue(true)
};// Focus on HOW objects collaborate
it('should coordinate user creation workflow', async () => {
await userService.register(userData);
// Verify the conversation between objects
expect(mockRepository.findByEmail).toHaveBeenCalledWith(userData.email);
expect(mockRepository.save).toHaveBeenCalledWith(
expect.objectContaining({ email: userData.email })
);
expect(mockNotifier.sendWelcome).toHaveBeenCalledWith('123');
});// Coordinate with integration test agents
describe('Swarm Test Coordination', () => {
beforeAll(async () => {
// Signal other swarm agents
await swarmCoordinator.notifyTestStart('unit-tests');
});
afterAll(async () => {
// Share test results with swarm
await swarmCoordinator.shareResults(testResults);
});
});// Define contracts for other swarm agents to verify
const userServiceContract = {
register: {
input: { email: 'string', password: 'string' },
output: { success: 'boolean', id: 'string' },
collaborators: ['UserRepository', 'NotificationService']
}
};// Share mock definitions across swarm
const swarmMocks = {
userRepository: createSwarmMock('UserRepository', {
save: jest.fn(),
findByEmail: jest.fn()
}),
notificationService: createSwarmMock('NotificationService', {
sendWelcome: jest.fn()
})
};// Test object conversations
it('should follow proper workflow interactions', () => {
const service = new OrderService(mockPayment, mockInventory, mockShipping);
service.processOrder(order);
const calls = jest.getAllMockCalls();
expect(calls).toMatchInlineSnapshot(`
Array [
Array ["mockInventory.reserve", [orderItems]],
Array ["mockPayment.charge", [orderTotal]],
Array ["mockShipping.schedule", [orderDetails]],
]
`);
});// Test how objects work together
describe('Service Collaboration', () => {
it('should coordinate with dependencies properly', async () => {
const orchestrator = new ServiceOrchestrator(
mockServiceA,
mockServiceB,
mockServiceC
);
await orchestrator.execute(task);
// Verify coordination sequence
expect(mockServiceA.prepare).toHaveBeenCalledBefore(mockServiceB.process);
expect(mockServiceB.process).toHaveBeenCalledBefore(mockServiceC.finalize);
});
});// Evolve contracts based on swarm feedback
describe('Contract Evolution', () => {
it('should adapt to new collaboration requirements', () => {
const enhancedMock = extendSwarmMock(baseMock, {
newMethod: jest.fn().mockResolvedValue(expectedResult)
});
expect(enhancedMock).toSatisfyContract(updatedContract);
});
});// Continuous contract verification
const contractMonitor = new SwarmContractMonitor();
afterEach(() => {
contractMonitor.verifyInteractions(currentTest.mocks);
contractMonitor.reportToSwarm(interactionResults);
});