|
1 | 1 | import axios from "axios";
|
| 2 | +import { assert } from "console"; |
2 | 3 |
|
3 | 4 | import config from "../config/config";
|
| 5 | +import { fetchQuery } from "../lib/requests"; |
4 | 6 | import queries from "../queries/queries";
|
5 | 7 |
|
6 | | -const testPostReq = async () => { |
7 | | - const data = await axios({ |
8 | | - url: "http://localhost:8000/api/v1/query", |
9 | | - method: "POST", |
10 | | - data: { |
11 | | - LEETCODE_SESSION: config.env.LEETCODE_SESSION, |
12 | | - CSRFTOKEN: config.env.CSRFTOKEN, |
13 | | - queryData: queries.getDailyChallengeQuery, |
14 | | - }, |
15 | | - }); |
16 | | - return data.data.data; |
17 | | -}; |
18 | | - |
19 | 8 | const test = () => {
|
20 | 9 | console.log(
|
21 | | - testPostReq().then((res) => |
| 10 | + fetchQuery(queries.getDailyChallengeQuery).then((res) => |
22 | 11 | // console.log(res.data.data.activeDailyCodingChallengeQuestion.question)
|
23 | 12 | console.log(res.data)
|
24 | 13 | )
|
25 | 14 | );
|
26 | 15 | };
|
27 | | - |
28 | | -test() |
| 16 | +const testBind = async () => { |
| 17 | + const getDailyChallenge = fetchQuery.bind( |
| 18 | + this, |
| 19 | + queries.getDailyChallengeQuery |
| 20 | + ); |
| 21 | + let data = null; |
| 22 | + await getDailyChallenge() |
| 23 | + .then((res) => (data=res)) |
| 24 | + .catch((err) => (data = null)); |
| 25 | + return data |
| 26 | +}; |
| 27 | +const main = async () => { |
| 28 | + test(); |
| 29 | + let res = await testBind(); |
| 30 | + if ( res!==null ) { |
| 31 | + console.log("✅ bind function working!!!") |
| 32 | + } |
| 33 | +}; |
| 34 | +main(); |
0 commit comments