refactor testing code for index method