Skip to content

Commit

Permalink
test: mockToken
Browse files Browse the repository at this point in the history
Co-Authored-By: Natalia Rodrigues <Natytotherodrigues@gmail.com>
  • Loading branch information
GabrielSMonteiro and Natyrodrigues committed Sep 19, 2024
1 parent 141b17a commit b3aa11c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/__tests__/watermelon.service.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,31 @@ describe('syncDatabaseWithServer', () => {
message: 'Success'
})
};

const mockToken = 'mockToken';
(AsyncStorage.getItem as jest.Mock).mockResolvedValue(mockToken);
(fetch as jest.Mock).mockResolvedValue(mockResponse);

(synchronize as jest.Mock).mockImplementation(async ({ pullChanges }) => {
const result = await pullChanges({
lastPulledAt: 0,
schemaVersion: 1,
migration: 1
});
return { changes: mockChanges, timestamp: mockTimestamp };
});

await syncDatabaseWithServer();

expect(AsyncStorage.getItem).toHaveBeenCalledWith('token');
expect(fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/usuario/sync/pull_users'),
expect.objectContaining({
method: 'GET',
headers: expect.objectContaining({
Authorization: `Bearer ${mockToken}`
})
})
);
});
});

0 comments on commit b3aa11c

Please sign in to comment.