SHARE
TWEET

Untitled

a guest Feb 27th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Parse } = global;
  2. const { Sensor: SensorCloudFunctions } = require('../cloud/functions');
  3.  
  4. let testUser;
  5.  
  6. const loginUser = async () => {
  7.   testUser = await Parse.User.logIn('test', 'test');
  8. };
  9.  
  10. const logOutUser = async () => {
  11.   Parse.User.logOut({ sessionToken: testUser.getSessionToken() });
  12. };
  13.  
  14. beforeAll(() => loginUser());
  15.  
  16. afterAll(() => logOutUser());
  17.  
  18. describe('Sensors Cloud Functions', () => {
  19.   test('findSensorsByDevices should return sensors without intersection', async () => {
  20.     const Device = Parse.Object.extend('Device');
  21.     const device = new Device();
  22.     device.set('uuid', 'test');
  23.     const Sensor = Parse.Object.extend('Sensor');
  24.     const sensor1 = new Sensor();
  25.     const sensor2 = new Sensor();
  26.     const sensor3 = new Sensor();
  27.     sensor1.set('device', device);
  28.     sensor1.set('name', 'sensor1');
  29.     sensor2.set('device', device);
  30.     sensor2.set('name', 'sensor2');
  31.     sensor3.set('device', device);
  32.     sensor3.set('name', 'sensor3');
  33.  
  34.     try {
  35.       await Promise.all([
  36.         device.save(null, { sessionToken: testUser.getSessionToken() }),
  37.         sensor1.save(null, { sessionToken: testUser.getSessionToken() }),
  38.         sensor2.save(null, { sessionToken: testUser.getSessionToken() }),
  39.         sensor3.save(null, { sessionToken: testUser.getSessionToken() }),
  40.       ]);
  41.  
  42.       const arrSensors = [sensor1, sensor2, sensor3];
  43.       const params = {
  44.         devices: [{ objectId: device._getId() }],
  45.       };
  46.       const { results } = await SensorCloudFunctions.findSensorsByDevices({
  47.         user: testUser,
  48.         params,
  49.       });
  50.       expect(results).toHaveLength(3);
  51.       expect(results.map((s) => s.objectId)).toEqual(arrSensors.map((s) => s._getId()));
  52.     } finally {
  53.       await Promise.all([
  54.         device.destroy({ sessionToken: testUser.getSessionToken() }),
  55.         sensor1.destroy({ sessionToken: testUser.getSessionToken() }),
  56.         sensor2.destroy({ sessionToken: testUser.getSessionToken() }),
  57.         sensor3.destroy({ sessionToken: testUser.getSessionToken() }),
  58.       ]);
  59.     }
  60.   });
  61. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top