Skip to content

Commit

Permalink
fix Sample service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SagivOnoApps committed Apr 26, 2020
1 parent 2766f63 commit d2bc72d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/components/Main/MapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ const MapModal = () => {
} = useSelector<Store, GeneralReducer>(state => state.general);
const {
strings: {
scanHome: { inDate, fromHour, wereYouThere, wasNotMe, wasMe, suspectedExposure, events, possibleExposure, atPlace, showOnMap },
scanHome: { inDate, fromHour },
},
} = useSelector<Store, LocaleReducer>(state => state.locale);



const [date, hour] = useMemo(() => {
const time = moment(properties?.fromTime);
return [time.format('DD.MM.YY'), time.format('DD.MM.YY')];
Expand Down
22 changes: 19 additions & 3 deletions src/services/__tests__/SampleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import { startSampling, insertDB, purgeSamplesDB, updateDBAccordingToSampleVeloc
import { onError } from '../ErrorService';
import * as db from '../../database/Database';
import { IS_LAST_POINT_FROM_TIMELINE, HIGH_VELOCITY_POINTS } from '../../constants/Constants';
import {startLocationTracking} from '../LocationService'


jest.mock('../WifiService', () => ({
getWifiList: jest.fn().mockResolvedValue(['ssdid']),
}));

jest.mock('../LocationService', () => ({
startLocationTracking: jest.fn()
}))

beforeEach(() => {
onError.mockClear();
db.mockClear();
AsyncStorage.mockClear();
startLocationTracking.mockClear()
});

afterEach(() => {
Expand All @@ -21,13 +28,22 @@ afterEach(() => {
describe('Sample Service', () => {
describe('startSampling', () => {
test('check resolves', async () => {
// onError.mockImplementationOnce(console.log);
expect(startSampling('en', { androidNotification: {} })).resolves.toBeTruthy();
startLocationTracking.mockResolvedValueOnce()
await startSampling('en', { androidNotification: {} })
expect(startLocationTracking).toBeCalledTimes(1)
});

test('check resolves for unknown language', async () => {
startLocationTracking.mockResolvedValueOnce()
expect(startSampling('ge', { androidNotification: {} })).resolves.toBeTruthy();
expect(startLocationTracking).toBeCalledTimes(1)
});

test('startLocationTracking reject', async () => {
startLocationTracking.mockRejectedValueOnce()
expect(startSampling('en', { androidNotification: {} })).rejects.toBeTruthy();
expect(startLocationTracking).toBeCalledTimes(1)
})
});

describe('insertDB', () => {
Expand Down Expand Up @@ -104,7 +120,7 @@ describe('Sample Service', () => {
// mock IS_LAST_POINT_FROM_TIMELINE
await AsyncStorage.setItem(IS_LAST_POINT_FROM_TIMELINE, 'true');
// return insertDB
expect(await updateDBAccordingToSampleVelocity(sample)).toBeTruthy();
await updateDBAccordingToSampleVelocity(sample)
});

test('with one point from DB', async () => {
Expand Down

0 comments on commit d2bc72d

Please sign in to comment.