Skip to content

Commit

Permalink
Fix factset id to uuid conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
geoah committed Mar 7, 2018
1 parent 891167d commit 80614a2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
4 changes: 2 additions & 2 deletions smartlogic/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ func TestTransformAndSendHandlers(t *testing.T) {
filePath: "../resources/multipleFactsetIds.json",
endpoint: "/transform",
expectedStatusCode: 200,
expectedResult: `{"uuid":"20db1bd6-59f9-4404-adb5-3165a448f8b0","concordances":[{"authority":"FACTSET","uuid":"a554dee7-f59e-3bf0-ae5c-ae86b0a851ca"},{"authority":"FACTSET","uuid":"717c3fac-8cd5-3271-bee0-b9fe2c2df78c"},{"authority":"FACTSET","uuid":"a3a59b75-046c-32a4-94ca-1a064e89a782"}]}`,
expectedResult: `{"uuid":"20db1bd6-59f9-4404-adb5-3165a448f8b0","concordances":[{"authority":"FACTSET","uuid":"8d3aba95-02d9-3802-afc0-b99bb9b1139e"},{"authority":"FACTSET","uuid":"3bc0ab41-c01f-3a0b-aa78-c76438080b52"},{"authority":"FACTSET","uuid":"f777c5af-e0b2-34dc-9102-e346ca2d27aa"}]}`,
}
transform_convertsTmeAndFactsetsAndReturnsPayload := testStruct{
scenarioName: "transform_convertsTmeAndFactsetsAndReturnsPayload",
filePath: "../resources/multipleTmeAndFactsetIds.json",
endpoint: "/transform",
expectedStatusCode: 200,
expectedResult: `{"uuid":"20db1bd6-59f9-4404-adb5-3165a448f8b0","concordances":[{"authority":"FT-TME","uuid":"e9f4525a-401f-3b23-a68e-e48f314cdce6"},{"authority":"FT-TME","uuid":"83f63c7e-1641-3c7b-81e4-378ae3c6c2ad"},{"authority":"FT-TME","uuid":"e4bc4ac2-0637-3a27-86b1-9589fca6bf2c"},{"authority":"FACTSET","uuid":"a554dee7-f59e-3bf0-ae5c-ae86b0a851ca"},{"authority":"FACTSET","uuid":"717c3fac-8cd5-3271-bee0-b9fe2c2df78c"},{"authority":"FACTSET","uuid":"a3a59b75-046c-32a4-94ca-1a064e89a782"}]}`,
expectedResult: `{"uuid":"20db1bd6-59f9-4404-adb5-3165a448f8b0","concordances":[{"authority":"FT-TME","uuid":"e9f4525a-401f-3b23-a68e-e48f314cdce6"},{"authority":"FT-TME","uuid":"83f63c7e-1641-3c7b-81e4-378ae3c6c2ad"},{"authority":"FT-TME","uuid":"e4bc4ac2-0637-3a27-86b1-9589fca6bf2c"},{"authority":"FACTSET","uuid":"8d3aba95-02d9-3802-afc0-b99bb9b1139e"},{"authority":"FACTSET","uuid":"3bc0ab41-c01f-3a0b-aa78-c76438080b52"},{"authority":"FACTSET","uuid":"f777c5af-e0b2-34dc-9102-e346ca2d27aa"}]}`,
}
send_convertsAndForwardsPayloadWithConcordance := testStruct{
scenarioName: "send_convertsAndForwardsPayloadWithConcordance",
Expand Down
2 changes: 1 addition & 1 deletion smartlogic/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func validateFactsetIdAndConvertToUuid(factsetId string) (string, error) {
if len(factsetId) != 8 || factsetId[0] != '0' || factsetId[6:8] != "-E" {
return "", errors.New("Bad Request: Concordance id " + factsetId + " is not a valid FACTSET Id")
}
return uuid.NewMD5(uuid.UUID{}, []byte(factsetId)).String(), nil
return convertFactsetIDToUUID(factsetId), nil
}

func validateSubstrings(subStrings []string) bool {
Expand Down
8 changes: 4 additions & 4 deletions smartlogic/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestValidateFactsetIdAndConvertToUuid(t *testing.T) {
invalidFactsetIdNoZeroPrefix := testStruct{testName: "invalidFactsetIdNoZeroPrefix", factsetId: "123456-E", expectedUuid: "", expectedError: errors.New("Bad Request: Concordance id 123456-E is not a valid FACTSET Id")}
invalidFactsetINoESuffix := testStruct{testName: "invalidFactsetINoESuffix", factsetId: "023456-A", expectedUuid: "", expectedError: errors.New("Bad Request: Concordance id 023456-A is not a valid FACTSET Id")}
invalidFactsetIdNoHyphenSuffix := testStruct{testName: "invalidFactsetIdNoHyphenSuffix", factsetId: "0123456E", expectedUuid: "", expectedError: errors.New("Bad Request: Concordance id 0123456E is not a valid FACTSET Id")}
validFactsetIdIsConverted := testStruct{testName: "validFactsetIdIsConverted", factsetId: "012345-E", expectedUuid: "65bd8174-7ea3-3176-aeb7-c9781666d8fb", expectedError: nil}
validFactsetIdIsConverted := testStruct{testName: "validFactsetIdIsConverted", factsetId: "012345-E", expectedUuid: "949a7e7f-2516-30c0-9123-f866601ffbe4", expectedError: nil}

testScenarios := []testStruct{invalidFactsetIdNoZeroPrefix, invalidFactsetINoESuffix, invalidFactsetIdNoHyphenSuffix, validFactsetIdIsConverted}

Expand Down Expand Up @@ -174,13 +174,13 @@ func TestConvertToUppConcordance(t *testing.T) {
ConcordedIds: []ConcordedId{
ConcordedId{
Authority: CONCORDANCE_AUTHORITY_FACTSET,
UUID: "a554dee7-f59e-3bf0-ae5c-ae86b0a851ca",
UUID: "8d3aba95-02d9-3802-afc0-b99bb9b1139e",
}, ConcordedId{
Authority: CONCORDANCE_AUTHORITY_FACTSET,
UUID: "717c3fac-8cd5-3271-bee0-b9fe2c2df78c",
UUID: "3bc0ab41-c01f-3a0b-aa78-c76438080b52",
}, ConcordedId{
Authority: CONCORDANCE_AUTHORITY_FACTSET,
UUID: "a3a59b75-046c-32a4-94ca-1a064e89a782",
UUID: "f777c5af-e0b2-34dc-9102-e346ca2d27aa",
},
},
}
Expand Down
14 changes: 14 additions & 0 deletions smartlogic/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package smartlogic

import (
"crypto/md5"

uuid "github.com/pborman/uuid"
)

func convertFactsetIDToUUID(factsetID string) string {
h := md5.New()
h.Write([]byte(factsetID))
md5One := h.Sum(nil)
return uuid.NewMD5(uuid.UUID{}, md5One).String()
}
35 changes: 35 additions & 0 deletions smartlogic/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package smartlogic

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestConvertFactsetIDToUUID_Success(t *testing.T) {
ids := []string{
"0DFC00-E",
"0C0NP2-E",
"0D0WTT-E",
"0CZQN1-E",
"0CBDM7-E",
"0CKQM0-E",
"0CKQM0-E",
"0D2QL9-E",
}

uuids := []string{
"3c409b48-1a47-3ae1-a1f0-4c77d7d4df99",
"bdd0438e-54d1-31bc-8748-a1a9a0bfb8ea",
"2a9ecb75-82d0-3e2c-b128-7e20093049d5",
"2da3ae10-110b-3d4a-bb8f-e0e3664f7ddd",
"8b92eeb6-6d6e-3c17-8620-c581ccfe6b13",
"e361ced1-e28d-3797-be40-1586d159b576",
"e361ced1-e28d-3797-be40-1586d159b576",
"33629787-d20d-396c-84d3-cb03362392c1",
}

for i, id := range ids {
assert.Equal(t, convertFactsetIDToUUID(id), uuids[i])
}
}

0 comments on commit 80614a2

Please sign in to comment.