Skip to content

Commit

Permalink
[ASI-837] Allow typescript + javascript interoperability in content-n…
Browse files Browse the repository at this point in the history
…ode (#2816)
  • Loading branch information
dmanjunath committed Apr 2, 2022
1 parent f2030ea commit 4360da3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions creator-node/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ tear_down () {

run_unit_tests () {
echo Running unit tests...
./node_modules/mocha/bin/mocha --timeout "${UNIT_TIMEOUT}" --recursive 'src/**/*.test.js' --exit
./node_modules/mocha/bin/mocha --require ts-node/register --timeout "${UNIT_TIMEOUT}" --recursive 'src/**/*.test.js' --exit
}

run_integration_tests () {
echo Running integration tests...
./node_modules/mocha/bin/mocha test/*.test.js --timeout "${INTEGRATION_TIMEOUT}" --exit
./node_modules/mocha/bin/mocha --require ts-node/register test/*.test.js --timeout "${INTEGRATION_TIMEOUT}" --exit
}

ARG1=${@:$OPTIND:1}
Expand Down
7 changes: 2 additions & 5 deletions creator-node/src/hashids.js → creator-node/src/hashids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ const MIN_LENGTH = 5
const hashids = new Hashids(HASH_SALT, MIN_LENGTH)

/** Encodes an int ID into a string. */
function encode(id) {
export function encode(id: number): string {
return hashids.encode([id])
}

/** Decodes a string id into an int. Returns null if an invalid ID. */
function decode(id) {
export function decode(id: string): number | null {
const ids = hashids.decode(id)
if (!ids.length) return null
return ids[0]
}

module.exports.encode = encode
module.exports.decode = decode
2 changes: 1 addition & 1 deletion creator-node/src/routes/tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {
} = require('../middlewares')

const { getCID } = require('./files')
const { decode } = require('../hashids.js')
const { decode } = require('../hashids')
const DBManager = require('../dbManager')
const { generateListenTimestampAndSignature } = require('../apiSigning.js')
const BlacklistManager = require('../blacklistManager')
Expand Down
3 changes: 2 additions & 1 deletion creator-node/test/dbManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ describe('Test deleteAllCNodeUserDataFromDB()', async () => {
cnodeUser,
cnodeUserUUID,
server,
libsMock
libsMock,
mockServiceRegistry

/** Init server to run DB migrations */
before(async () => {
Expand Down
15 changes: 7 additions & 8 deletions creator-node/test/pollingTracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ describe('test Polling Tracks with mocks', function () {
let app,
server,
libsMock,
handleTrackContentRoute
handleTrackContentRoute,
mockServiceRegistry
let session, userId, userWallet

const spId = 1
Expand Down Expand Up @@ -840,7 +841,8 @@ describe('test Polling Tracks with real files', function () {
session,
libsMock,
handleTrackContentRoute,
userId
userId,
mockServiceRegistry

/** Inits libs mock, web server app, blacklist manager, and creates starter CNodeUser */
beforeEach(async () => {
Expand Down Expand Up @@ -1071,8 +1073,7 @@ describe('test Polling Tracks with real files', function () {
.set('User-Id', userId)
.send(trackMetadata)
.expect(200)
trackMetadataMultihash = trackMetadataResp.body.data.metadataMultihash
trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID
const trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID

// Complete track creation
await request(app2)
Expand Down Expand Up @@ -1124,8 +1125,7 @@ describe('test Polling Tracks with real files', function () {
.set('User-Id', userId)
.send(trackMetadata)
.expect(200)
trackMetadataMultihash = trackMetadataResp.body.data.metadataMultihash
trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID
const trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID

// Upload track 2 metadata
const track2Metadata = {
Expand All @@ -1141,8 +1141,7 @@ describe('test Polling Tracks with real files', function () {
.set('User-Id', userId)
.send(track2Metadata)
.expect(200)
track2MetadataMultihash = track2MetadataResp.body.data.metadataMultihash
track2MetadataFileUUID = track2MetadataResp.body.data.metadataFileUUID
const track2MetadataFileUUID = track2MetadataResp.body.data.metadataFileUUID

// Complete track1 creation
await request(app2)
Expand Down
2 changes: 1 addition & 1 deletion creator-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"baseUrl": "./src",
"pretty": true,
"target": "es2020",
"module": "es2020",
"module": "commonjs",
"lib": [
"es2020"
],
Expand Down

0 comments on commit 4360da3

Please sign in to comment.