This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add method for retrieving a user's QR code
- Loading branch information
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { BaseResponseData } from './request'; | ||
|
||
export interface QRCodeRequest { | ||
/** The internal version to use; currently 4 */ | ||
schema_type: number; | ||
|
||
/** The ID of the user to get a QR code for */ | ||
object_id: string; | ||
} | ||
|
||
export interface QRCodeResponse extends BaseResponseData { | ||
/** Contains a link to the QR code */ | ||
qrcode_url: { | ||
/** An in-app link to the QR code */ | ||
uri: string; | ||
|
||
/** Contains a public link to the QR code image (first element in array) */ | ||
url_list: string[]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import TikTokAPI, { QRCodeResponse } from '../src'; | ||
import { | ||
loadTestData, | ||
mockConfig, | ||
mockParams, | ||
} from './util'; | ||
|
||
describe('#getQRCode()', () => { | ||
it('a successful response should match the interface', async () => { | ||
const api = new TikTokAPI(mockParams, mockConfig); | ||
const mock = new MockAdapter(api.request); | ||
const userId = '9999999999999999999'; | ||
|
||
mock | ||
.onPost(new RegExp('aweme/v1/fancy/qrcode/info/\?.*')) | ||
.reply(200, loadTestData('getQRCode.json'), {}); | ||
|
||
const res = await api.getQRCode(userId); | ||
const expected: QRCodeResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
qrcode_url: { | ||
uri: 'musically-qrcode/1111111111111111111', | ||
url_list: [ | ||
'http://p16.muscdn.com/img/musically-qrcode/1111111111111111111~c5_720x720.image', | ||
], | ||
}, | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"qrcode_url": { | ||
"uri": "musically-qrcode/1111111111111111111", | ||
"url_list": [ | ||
"http://p16.muscdn.com/img/musically-qrcode/1111111111111111111~c5_720x720.image" | ||
] | ||
}, | ||
"status_code": 0 | ||
} |