stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
66 lines • 2.33 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setUser = exports.getTestClientWithUser = exports.getTestClient = exports.getRandomInt = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _streamChat = require("stream-chat");
var apiKey = 'API_KEY';
var token = 'dummy_token';
var setUser = (client, user) => new Promise(resolve => {
var c = client;
c.connectionId = 'dumm_connection_id';
c.user = {
...user,
mutes: []
};
c._user = {
...c.user
};
c.userID = user.id;
c.userToken = token;
resolve();
});
exports.setUser = setUser;
function mockClient(client, options = {}) {
var _options$disableAppSe = options.disableAppSettings,
disableAppSettings = _options$disableAppSe === void 0 ? true : _options$disableAppSe;
var c = client;
var withPrivates = c;
jest.spyOn(withPrivates, '_setToken').mockImplementation();
jest.spyOn(withPrivates, '_setupConnection').mockImplementation();
c.tokenManager = {
getToken: jest.fn(() => token),
tokenReady: jest.fn(() => true)
};
c.setUser = setUser.bind(null, client);
if (disableAppSettings) {
c.getAppSettings = jest.fn(() => ({}));
}
return client;
}
var getTestClient = (options = {}) => mockClient(new _streamChat.StreamChat(apiKey), options);
exports.getTestClient = getTestClient;
var getTestClientWithUser = exports.getTestClientWithUser = function () {
var _ref = (0, _asyncToGenerator2.default)(function* (user, options = {}) {
var _options$disableAppSe2 = options.disableAppSettings,
disableAppSettings = _options$disableAppSe2 === void 0 ? true : _options$disableAppSe2;
var client = mockClient(new _streamChat.StreamChat(apiKey));
yield setUser(client, user);
client.wsPromise = Promise.resolve();
if (disableAppSettings) {
client.getAppSettings = jest.fn(() => ({}));
}
return client;
});
return function getTestClientWithUser(_x) {
return _ref.apply(this, arguments);
};
}();
var getRandomInt = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
exports.getRandomInt = getRandomInt;
//# sourceMappingURL=mock.js.map