Add tests for client-id / app name parsing

Summary: Add tests for client-id / app name parsing. We've had a lot of bugs here in the past. Get some good test coverage so we have some assurance the shared utils for it won't be broken.

Reviewed By: jknoxville

Differential Revision: D18830269

fbshipit-source-id: 07c9755bbeae28c48580f44453d4010d6d3830b0
This commit is contained in:
Anton Nikolaev
2019-12-05 06:28:31 -08:00
committed by Facebook Github Bot
parent 94ce34066b
commit 006003ae6b

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {deconstructClientId, buildClientId} from '../clientUtils';
test('client id constructed correctly', () => {
const consoleErrorSpy = jest.spyOn(global.console, 'error');
const clientId = buildClientId({
app: 'Instagram',
os: 'iOS',
device: 'iPhone Simulator',
device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
});
expect(clientId).toBe(
'Instagram#iOS#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
);
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
});
test('client id deconstructed correctly', () => {
const deconstructedClientId = deconstructClientId(
'Instagram#iOS#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
);
expect(deconstructedClientId).toStrictEqual({
app: 'Instagram',
os: 'iOS',
device: 'iPhone Simulator',
device_id: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
});
});
test('client id deconstruction error logged', () => {
const consoleErrorSpy = jest.spyOn(global.console, 'error');
const deconstructedClientId = deconstructClientId(
'Instagram#iPhone Simulator#EC431B79-69F1-4705-9FE5-9AE5D96378E1',
);
expect(deconstructedClientId).toStrictEqual({
app: 'Instagram',
os: 'iPhone Simulator',
device: 'EC431B79-69F1-4705-9FE5-9AE5D96378E1',
device_id: undefined,
});
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
});