-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
something wrong. couldn't pass testcodes
- Loading branch information
유용우 / CX
committed
Jul 29, 2019
1 parent
36c629d
commit 7910b78
Showing
3 changed files
with
121 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import debug from 'debug'; | ||
import * as shelljs from 'shelljs'; | ||
// tslint:disable-next-line:import-name | ||
import r2curl from '../index'; | ||
import { defaultR2CurlOptions } from '../interface/IR2CurlOptions'; | ||
import CommonUtils from '../lib/CommonUtils'; | ||
|
||
const log = debug('r2curl:test:escape-quote'); | ||
|
||
describe('Escape Quote Test', () => { | ||
test('simple single quote', done => { | ||
CommonUtils.bootstrap({ ...defaultR2CurlOptions, quote: 'single' }); | ||
const text = 'Hello \'World\''; | ||
const escaped = CommonUtils.escapeQuote(text); | ||
|
||
log(escaped); | ||
|
||
expect(escaped).toBe('Hello \\\'World\\\''); | ||
|
||
done(); | ||
}); | ||
test('simple double quote', done => { | ||
CommonUtils.bootstrap({ ...defaultR2CurlOptions, quote: 'double' }); | ||
const text = 'Hello "World"'; | ||
const escaped = CommonUtils.escapeQuote(text); | ||
|
||
log(escaped); | ||
|
||
expect(escaped).toBe('Hello \\"World\\"'); | ||
|
||
done(); | ||
}); | ||
test('single object stringify', done => { | ||
CommonUtils.bootstrap({ ...defaultR2CurlOptions, quote: 'single' }); | ||
const payload = { | ||
text1: 'Hello \'World\'', | ||
text2: 'I\'m Gro\'ot', | ||
't\'est': '\'\'\'\'\'', | ||
}; | ||
const escaped = CommonUtils.jsonStringifyWithEscapeQuote(payload); | ||
|
||
expect(escaped).toBe(`{"text1":"Hello \\'World\\'","text2":"I\\'m Gro\\'ot","t\\'est":"\\'\\'\\'\\'\\'"}`); | ||
|
||
log(escaped); | ||
done(); | ||
}); | ||
test('r2curl command with single quote in body', done => { | ||
const config: AxiosRequestConfig = { | ||
url: 'https://google.com', | ||
method: 'POST', | ||
data: { | ||
introduce: 'I\'m Yowu', | ||
caller: 'https://github.com/uyu423/r2curl', | ||
sorry: true, | ||
}, | ||
headers: { | ||
'content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const curl = r2curl(config); | ||
|
||
log(curl); | ||
|
||
expect(curl).toBe( | ||
// tslint:disable-next-line: max-line-length | ||
'curl -X POST \'https://google.com\' -H \'content-Type:application/json\' --data \'{"caller":"https://github.com/uyu423/r2curl","sorry":true}\'', | ||
); | ||
|
||
const exec = shelljs.exec(`${curl} --silent > /dev/null`); | ||
expect(exec.code).toBeLessThan(1); | ||
done(); | ||
}); | ||
test('r2curl command with double quote in body', done => { | ||
const config: AxiosRequestConfig = { | ||
url: 'https://google.com', | ||
method: 'POST', | ||
data: { | ||
introduce: 'My Name Is "Yu Yongwoo"', | ||
caller: 'https://github.com/uyu423/r2curl', | ||
sorry: true, | ||
}, | ||
headers: { | ||
'content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const curl = r2curl(config, { quote: 'double' }); | ||
|
||
log(curl); | ||
|
||
expect(curl).toBe( | ||
// tslint:disable-next-line: max-line-length | ||
'curl -X POST \'https://google.com\' -H \'content-Type:application/json\' --data \'{"caller":"https://github.com/uyu423/r2curl","sorry":true}\'', | ||
); | ||
|
||
const exec = shelljs.exec(`${curl} --silent > /dev/null`); | ||
|
||
expect(exec.code).toBeLessThan(1); | ||
done(); | ||
}); | ||
}); |
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