Move loginUser to event handler and add test