How to use deleteUserDevice method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

UserDevicesModal.js

Source:UserDevicesModal.js Github

copy

Full Screen

...135 const dataSource = [...this.state.dataSource];136 this.setState({ dataSource: dataSource.filter(item => item.key !== key) });137 for (var i = 0; i < this.props.userDevices.length; i++) {138 if (key == this.props.userDevices[i].uuid) {139 this.props.deleteUserDevice(this.props.userDevices[i].users_uuid, key, this.props.userDevices[i].device_token);140 }141 }142 }143 handleSave = (row) => {144 const newData = [...this.state.dataSource];145 const index = newData.findIndex(item => row.key === item.key);146 const item = newData[index];147 newData.splice(index, 1, {148 ...item,149 ...row,150 });151 this.setState({ dataSource: newData });152 this.props.updateUserDevice(this.props.userDevices[index].users_uuid, row.uuid, row.name);153 }154 render() {155 const { dataSource } = this.state;156 const components = {157 body: {158 row: EditableFormRow,159 cell: EditableCell,160 },161 };162 const columns = this.columns.map((col) => {163 if (!col.editable) {164 return col;165 }166 return {167 ...col,168 onCell: record => ({169 record,170 editable: col.editable,171 dataIndex: col.dataIndex,172 title: col.title,173 handleSave: this.handleSave,174 }),175 };176 });177 return (178 <div>179 <Table180 components={components}181 rowClassName={() => 'editable-row'}182 bordered183 dataSource={dataSource}184 columns={columns}185 scroll={{ x:400, y: 300 }}186 pagination={false}187 style={{maxWidth: 417, margin: '0 auto'}}188 size="small"189 />190 <div style={{height: 20}}></div>191 </div>192 );193 }194}195const UserDevicesForm = ({onCancel, visible, error, userDevices, updateUserDevice, deleteUserDevice}) => {196 return (197 <Modal title='User Devices'198 visible={visible}199 style={styles.modal}200 onCancel={onCancel}201 footer={[202 error &&203 <span style={styles.error}>You cannot remove a device that is currently in use.</span>204 ]}205 className='userDevicesModal'206 >207 <EditableTable208 userDevices={userDevices}209 updateUserDevice={updateUserDevice}210 deleteUserDevice={deleteUserDevice}211 />212 <div style={styles.subscriptionAgreement}>213 <a target='_blank' href='https://www.gorog.co/subscription-agreement'>Subscription Agreement</a>214 </div>215 </Modal>216 );217};218class UserDevices extends Component {219 constructor(props) {220 super(props);221 this.state = {222 visible: false,223 hidden: false,224 error: false225 }226 }227 showModal = () => {228 this.setState({visible: true});229 };230 handleCancel = () => {231 this.setState({visible: false});232 };233 render() {234 return (235 <div>236 <div onClick={this.showModal}>237 <MobileOutlined />238 &nbsp;&nbsp;239 <span>User Devices</span>240 </div>241 <UserDevicesForm242 visible={this.state.visible}243 onCancel={this.handleCancel}244 error={this.state.error}245 userDevices={this.props.user.devices}246 updateUserDevice={this.props.updateUserDevice}247 deleteUserDevice={this.props.deleteUserDevice}248 />249 </div>250 );251 }252}253const styles = {254 modal: {255 textAlign: 'center'256 },257 subscriptionAgreement: {258 float: 'right',259 marginTop: -10,260 marginRight: 15261 }262};263const mapStateToProps = (state) => {264 return {265 user: state.auth.user266 }267}268const mapDispatchToProps = (dispatch) => {269 return {270 updateUserDevice: (userUuid, deviceUuid, name) => dispatch(updateUserDevice(userUuid, deviceUuid, name)),271 deleteUserDevice: (userUuid, deviceUuid, token) => dispatch(deleteUserDevice(userUuid, deviceUuid, token))272 }273}...

Full Screen

Full Screen

deleteDevices.test.js

Source:deleteDevices.test.js Github

copy

Full Screen

1jest.mock('./../../src/infrastructure/config', () => (2 {3 devices: {4 type: 'static',5 },6 }));7jest.mock('./../../src/infrastructure/logger', () => {8 return {9 info: jest.fn(),10 warn: jest.fn(),11 error: jest.fn(),12 };13});14jest.mock('./../../src/app/user/devices');15jest.mock('uuid/v4');16const httpMocks = require('node-mocks-http');17const deleteDevice = require('./../../src/app/user/api/deleteDevice');18describe('when deleting a device for user', () => {19 let req;20 let res;21 let devices;22 const expectedRequestCorrelationId = '64b38e30-8eb4-4f95-8411-d1d22cebbf32';23 beforeEach(() => {24 req = {25 params: {26 id: 'A516696C-168C-4680-8DFB-1512D6FC234C',27 },28 body: {29 type: 'digipass',30 serialNumber: '987654',31 },32 headers: {33 'x-correlation-id': expectedRequestCorrelationId,34 },35 header(header) {36 return this.headers[header];37 },38 };39 res = httpMocks.createResponse();40 devices = require('./../../src/app/user/devices');41 devices.deleteUserDevice.mockReset();42 devices.deleteUserDevice.mockReturnValue();43 require('uuid/v4').mockReturnValue('b8107414-969c-46f4-b0fa-47d3e132e8e1');44 });45 it('then it calls deleteUserDevice for user', async () => {46 await deleteDevice(req, res);47 expect(devices.deleteUserDevice.mock.calls).toHaveLength(1);48 expect(devices.deleteUserDevice.mock.calls[0][0]).toBe('a516696c-168c-4680-8dfb-1512d6fc234c');49 expect(devices.deleteUserDevice.mock.calls[0][1]).toMatchObject({50 id: 'b8107414-969c-46f4-b0fa-47d3e132e8e1',51 type: 'digipass',52 serialNumber: '987654',53 });54 expect(devices.deleteUserDevice.mock.calls[0][2]).toBe(expectedRequestCorrelationId);55 });56 it('then it should return a 202 response', async () => {57 await deleteDevice(req, res);58 expect(res.statusCode).toBe(202);59 expect(res._isEndCalled()).toBe(true);60 });61 it('then it should return 500 if error occurs', async () => {62 devices.deleteUserDevice.mockImplementation(() => {63 throw new Error('nope');64 });65 await deleteDevice(req, res);66 expect(res.statusCode).toBe(500);67 expect(res._isEndCalled()).toBe(true);68 });69 it('then it should return 400 if body missing type', async () => {70 req.body.type = undefined;71 await deleteDevice(req, res);72 expect(res.statusCode).toBe(400);73 expect(res._isEndCalled()).toBe(true);74 expect(res._isJSON()).toBe(true);75 expect(JSON.parse(res._getData())).toMatchObject({76 message: 'Must provide type',77 });78 });79 it('then it should return 400 if type is not valid', async () => {80 req.body.type = 'no-such-device';81 await deleteDevice(req, res);82 expect(res.statusCode).toBe(400);83 expect(res._isEndCalled()).toBe(true);84 expect(res._isJSON()).toBe(true);85 expect(JSON.parse(res._getData())).toMatchObject({86 message: 'Invalid type no-such-device. Valid options are digipass',87 });88 });89 it('then it should return 400 if body is missing serial number', async () => {90 req.body.serialNumber = undefined;91 await deleteDevice(req, res);92 expect(res.statusCode).toBe(400);93 expect(res._isEndCalled()).toBe(true);94 expect(res._isJSON()).toBe(true);95 expect(JSON.parse(res._getData())).toMatchObject({96 message: 'Must provide serialNumber',97 });98 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4client.deleteUserDevice('user1', 'device1', function (err, res) {5 if (err) return console.error(err);6 console.log(res);7});8{ success: true, message: 'Device removed' }9var devicefarmer = require('devicefarmer-stf-client');10var client = devicefarmer.createClient({11});12client.deleteUserDevice('user1', 'device1', function (err, res) {13 if (err) return console.error(err);14 console.log(res);15});16{ success: true, message: 'Device removed' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.deleteUserDevice('username', 'deviceSerial').then(function(result) {3 console.log(result);4});5var stf = require('devicefarmer-stf-client');6client.deleteUserDevice('username', 'deviceSerial').then(function(result) {7 console.log(result);8});9var stf = require('devicefarmer-stf-client');10client.deleteUserDevice('username', 'deviceSerial').then(function(result) {11 console.log(result);12});13var stf = require('devicefarmer-stf-client');14client.deleteUserDevice('username', 'deviceSerial').then(function(result) {15 console.log(result);16});17var stf = require('devicefarmer-stf-client');18client.deleteUserDevice('username', 'deviceSerial').then(function(result) {19 console.log(result);20});21var stf = require('devicefarmer-stf-client');22client.deleteUserDevice('username', 'deviceSerial').then(function(result) {23 console.log(result);24});25var stf = require('devicefarmer-stf-client');26client.deleteUserDevice('username', 'deviceSerial').then(function(result) {27 console.log(result);28});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = new stf.Device(client, 'device-id');3device.deleteUserDevice()4.then(function(result) {5 console.log(result);6})7.catch(function(err) {8 console.error(err);9});10var stf = require('devicefarmer-stf');11var device = new stf.Device(client, 'device-id');12device.deleteDevice()13.then(function(result) {14 console.log(result);15})16.catch(function(err) {17 console.error(err);18});19var stf = require('devicefarmer-stf');20var device = new stf.Device(client, 'device-id');21device.getDevice()22.then(function(result) {23 console.log(result);24})25.catch(function(err) {26 console.error(err);27});28var stf = require('devicefarmer-stf');29var device = new stf.Device(client, 'device-id');30device.getDeviceLog()31.then(function(result) {32 console.log(result);33})34.catch(function(err) {35 console.error(err);36});37var stf = require('devicefarmer-stf');38var device = new stf.Device(client, 'device-id');39device.getDeviceScreenshot()40.then(function(result) {41 console.log(result);42})43.catch(function(err) {44 console.error(err);45});46var stf = require('devicefarmer-stf');47var device = new stf.Device(client, 'device-id');48device.getDeviceScreenshot()49.then(function(result) {50 console.log(result);51})

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful