Skip to content

Commit

Permalink
tests: in watt-time refactored tests, moved mock functions to corresp…
Browse files Browse the repository at this point in the history
…onding folder
  • Loading branch information
manushak committed Feb 7, 2024
1 parent 3be384a commit c1a9221
Show file tree
Hide file tree
Showing 2 changed files with 370 additions and 343 deletions.
79 changes: 79 additions & 0 deletions src/__mocks__/watt-time/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as DATA from './data.json';

export function getMockResponse(url: string, data: any) {
switch (url) {
case 'https://api2.watttime.org/v2/login':
if (
data?.auth?.username === 'test1' &&
data?.auth?.password === 'test2'
) {
return Promise.resolve({
status: 200,
data: {
token: 'test_token',
},
});
}
return Promise.resolve({
status: 401,
data: {},
});

case 'https://apifail.watttime.org/v2/login': {
if (
data?.auth?.username === 'test1' &&
data?.auth?.password === 'test2'
) {
return Promise.resolve({
status: 200,
data: {
token: 'test_token',
},
});
}
return Promise.resolve({
status: 401,
data: {},
});
}
case 'https://apifail2.watttime.org/v2/login':
return Promise.resolve({
status: 200,
data: {
token: 'test_token',
},
});
case 'https://apifail3.watttime.org/v2/login':
return Promise.resolve({
status: 200,
data: {
token: 'test_token',
},
});
case 'https://api2.watttime.org/v2/data':
return Promise.resolve({
data: DATA,
status: 200,
});
case 'https://apifail.watttime.org/v2/data':
return Promise.resolve({
status: 400,
data: {},
});
case 'https://apifail2.watttime.org/v2/data':
return Promise.resolve({
status: 200,
data: {
none: {},
},
});
case 'https://apifail3.watttime.org/v2/data':
return Promise.reject({
status: 401,
data: {
none: {},
},
});
}
return Promise.resolve({});
}
Loading

0 comments on commit c1a9221

Please sign in to comment.