Skip to content

Commit

Permalink
feat: support nested objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kkweon committed Jun 25, 2021
1 parent 8edbd3b commit d1081f7
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 9 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx pretty-quick --staged
186 changes: 185 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"format": "prettier \"*.{js,ts,json,yml,yaml,md}\" \"src/**/*.{ts,js,json}\" \".github/**/*.{yml,yaml}\" --write",
"clean": "rm -rf dist",
"protoc": "protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:. --ts_out=. src/**/*.proto",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"prepare": "husky install"
},
"devDependencies": {
"@semantic-release/git": "^9.0.0",
Expand All @@ -55,8 +56,10 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^6.0.0",
"jest": "^27.0.3",
"prettier": "^2.3.0",
"pretty-quick": "^3.1.1",
"semantic-release": "^17.4.3",
"ts-jest": "^27.0.2",
"ts-protoc-gen": "^0.15.0",
Expand Down
26 changes: 26 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ describe('index', () => {
})

it('should convert the ProtoMessage to string', () => {
expect.hasAssertions()
expect(convertProtoMessageToString(getSimpleProtoMessage())).toStrictEqual(`
message Root {
string field_name = 1;
}`)
})

it('should convert multiple primitive fields to string', () => {
expect.hasAssertions()
const protoMessage = getSimpleProtoMessage()
protoMessage.addFields(
getPrimitiveProtoField(
Expand Down Expand Up @@ -57,6 +59,30 @@ message Root {
bool bool_name = 2;
int64 int64_name = 3;
double double_name = 4;
}`)
})

it('should convert nested objects', () => {
expect.hasAssertions()
const input = {
code: 100,
msg: 'success',
result: {
token:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NSJ9.slBCWsGnvLyUCVIjaLHlS67rNqyWAd1f9BB6D1oc7d0',
},
}

expect(convertProtoMessageToString(parseRootObjectToProtoMessage(input)))
.toStrictEqual(`
message Root {
int64 code = 1;
string msg = 2;
message Result {
string token = 1;
}
Result result = 3;
}`)
})
})
Expand Down
Loading

0 comments on commit d1081f7

Please sign in to comment.