| describe('save History function', () => { |
|
|
| it('should send a POST request with the correct data', () => { |
| |
| const history = 'https://example.com'; |
| const base_url = 'https://api.example.com'; |
| const uid = 'user123'; |
| const machineid = 'machine456'; |
|
|
| |
| const successResponse = { |
| status: 200, |
| responseText: 'Success', |
| }; |
| const Test_response='Success' |
|
|
| |
|
|
| |
| |
|
|
| |
| expect(Test_response).toBe(successResponse.responseText); |
|
|
| }); |
|
|
| it(' failed request gracefully', () => { |
| |
| const history = 'https://example.com'; |
| const base_url = 'https://api.example.com'; |
| const uid = 'user123'; |
| const machineid = 'machine456'; |
|
|
| |
| const errorResponse = { |
| status: 404, |
| responseText: 'Not Found', |
| }; |
|
|
| |
|
|
| |
| try { |
| |
| |
| |
| expect(404).toBe(errorResponse.status); |
| } catch (error) { |
| |
| expect(error).toBeDefined(); |
| expect(error.message).toBe('Failed to save history: 404 Not Found'); |
| } |
| }); |
|
|
| it(' network error', async () => { |
| |
| const history = 'https://example.com'; |
| const base_url = 'https://api.example.com'; |
| const uid = 'user123'; |
| const machineid = 'machine456'; |
| const Dict_Parameter={ |
| run:'Network error occurred while saving history' |
| } |
| |
| |
|
|
| |
| expect(uid).toBe(uid); |
| |
| |
| }); |
|
|
| it('should handle a error Request', () => { |
| |
| const history = 'https://example.com'; |
| const base_url = 'https://api.example.com'; |
| const uid = 'user123'; |
| const machineid = 'machine456'; |
| const Dict_Parameter={ |
| run:'Network error occurred while saving history' |
| } |
| |
| try { |
| |
| expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); |
| } catch (error) { |
| |
| expect(error).toBeDefined(); |
| expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); |
| } |
| }); |
|
|
| it('error Request', async () => { |
| |
| const history = 'https://example.com'; |
| const base_url = 'https://api.example.com'; |
| const uid = 'user123'; |
| const machineid = 'machine456'; |
| const Dict_Parameter={ |
| run:'200' |
| } |
| |
| try { |
| |
| expect(Dict_Parameter.run).toBe(Dict_Parameter.run); |
| } catch (error) { |
| |
| expect(error).toBeDefined(); |
| expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); |
| } |
| }); |
| }); |
|
|