Skip to content

Commit

Permalink
Add tests (#9)
Browse files Browse the repository at this point in the history
Also, turn off the 'set -x' in put_comments, I believe that will
leak credentials to logfiles.
  • Loading branch information
Eric Fischer authored Mar 30, 2018
1 parent 40c10ad commit 221d5f7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_js:

script:
- npm run lint
- npm run test
- npm run test_compile
- npm run test_comments
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ usage: `$(npm bin)/reactifex <input_folder> <output_file>`

This mode is why I wrote this library in the first place - I wanted the ability to use comments as `PO` files do, but none of the tools I found to convert react-intl messages to `PO` files were able to properly handle ICU pluralization. By keeping everything in a js context with `KEYVALUEJSON`, plurals work correctly *and* we now have comment support for translators (by default, Transifex's `KEYVALUEJSON` file format does not allow for comments to be included with strings for translation).

Note that tests for this mode aren't included, as it relies on Transifex's API being up and responsive.

Usage is a little complicated, I'm sorry about that; you're going to be running this server-side as a series of bash commands. Do note that I assume `$SECRET_USER` and `$SECRET_PWD` env vars exist for basic auth purposes. See [Transifex's API Introduction](https://docs.transifex.com/api/introduction) for more details on authentication. Here's an example, written as it would be in the Makefile of a project that makes use of reactifex:

```
Expand Down
18 changes: 18 additions & 0 deletions bash_scripts/hashmap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"key": "testMessage",
"string_hash": "12345deadbeef"
},
{
"key": "anotherTestMessage",
"string_hash": "8badf00d"
},
{
"key": "testMessage_extra",
"string_hash": "bada55"
},
{
"key": "anotherTestMessage_extra",
"string_hash": "feedface9876"
}
]
4 changes: 4 additions & 0 deletions bash_scripts/put_comments.sh
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#!/bin/bash
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $112345deadbeef
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $18badf00d
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $1bada55
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $1feedface9876
2 changes: 0 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if (process.argv[3] === "--comments") {
var messageInfo = JSON.parse(fs.readFileSync(__dirname + "/bash_scripts/hashmap.json"));
var scriptPath = __dirname + "/bash_scripts/put_comments.sh";
fs.writeFileSync(scriptPath, "#!/bin/bash\n");
fs.writeFileSync(scriptPath, "set -x\n");
inData.forEach((message) => {
var info = messageInfo.find(mi => mi.key == message.id);
if (info) {
Expand All @@ -38,7 +37,6 @@ if (process.argv[3] === "--comments") {
process.stdout.write("string " + message.id + " does not yet exist on transifex!\n");
}
});
fs.writeFileSync(scriptPath, "set +x\n");
} else {
fs.writeFileSync(process.argv[3], JSON.stringify(outData, null, 2));
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "reactifex",
"version": "1.0.0",
"version": "1.0.1",
"description": "A helper for moving react-intl messages to transifex and back",
"bin": "./main.js",
"scripts": {
"lint": "eslint .",
"test": "node main.js test_data/input/ test_data/test_output.json && diff test_data/test_output.json test_data/expected_output/messages.json"
"test_compile": "node main.js test_data/input/ test_data/test_output.json && diff test_data/test_output.json test_data/expected_output/messages.json",
"test_comments": "node main.js test_data/input/ --comments && diff bash_scripts/put_comments.sh test_data/expected_output/put_comments.sh"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions test_data/expected_output/put_comments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $112345deadbeef
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $18badf00d
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"It's a message, for testing\"}" $1bada55
curl -L -w "\n" --user $SECRET_USER:$SECRET_PWD -X PUT -H "Content-Type: application/json" --data "{\"comment\": \"Also a message for testing\"}" $1feedface9876

0 comments on commit 221d5f7

Please sign in to comment.