Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MAIN_DB_NAME=paybutton-test
MAIN_DB_PASSWORD=paybutton-password
MAIN_DB_ROOT_PASSWORD=paybutton-root-password
MAIN_DB_USER=paybutton-user-test
MAIN_DB_HOST=localhost
MAIN_DB_HOST=paybutton-db
MAIN_DB_PORT=3306

SUPERTOKENS_DB_USER=st-user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Integration Test
name: Pull Request Tests
on:
pull_request:
branches:
- master
jobs:
test:
name: Integration Tests
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -14,6 +14,8 @@ jobs:
fetch-depth: 0
- name: Install Dependencies
run: yarn
- name: Run unit tests
run: make github-test-unit
- name: Add local env file
run: touch .env.local
- name: Spin up required database containers
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ github-test-integration:
sleep 15
$(create_test_paybutton_json)
$(touch_local_env)
#sed -i "s/db/localhost/g" .env.test
#sed -i "s/paybutton-cache/localhost/g" .env.test
sed -i "s/MAIN_DB_HOST=paybutton-db/MAIN_DB_HOST=localhost/g" .env.test
yarn ci:integration:test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"ioredis": "^5.2.4",
"jest": "^28.1.0",
"jest": "^29.7.0",
"jest-mock-extended": "^2.0.6",
"lint-staged": "^12.4.1",
"nodemailer": "^6.9.15",
"nodemon": "^2.0.4",
"redis": "^4.5.1",
"ts-jest": "^28.0.2",
"ts-jest": "^29.2.5",
"ts-node": "^8.10.2",
"tsx": "^3.12.1",
"typescript": "^5.7.2"
Expand Down
4 changes: 4 additions & 0 deletions scripts/docker-exec-shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ case "$command" in
eval "$base_command_db" mariadb -h "$MAIN_DB_HOST" -u "$SUPERTOKENS_DB_USER" -p"$SUPERTOKENS_DB_PASSWORD" -D supertokens "$@"
;;
"test" | "t")
eval "$base_command_node" yarn test --silent --verbose=false "$@"
;;
"testfull" | "tf")
eval "$base_command_node" yarn test "$@"
;;
"testwatch" | "tw")
Expand Down Expand Up @@ -150,6 +153,7 @@ case "$command" in
echo " dbt, databasetest [$db_container_name] enter the mariadb command-line using the test db"
echo " dbu, databaseuser [$db_container_name] enter the mariadb command-line using the users db"
echo " t, test [$node_container_name] run tests"
echo " tf, testfull [$node_container_name] run tests, show full output"
echo " tw, testwatch [$node_container_name] run tests watching it"
echo " tc, testcoverage [$node_container_name] test coverage"
echo " ns, nodeshell [$node_container_name] enter the node container"
Expand Down
20 changes: 15 additions & 5 deletions tests/unittests/chronikService.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { EMPTY_OP_RETURN } from 'utils/validators'
import { getNullDataScriptData } from '../../services/chronikService'

jest.mock('../../services/chronikService', () => {
return {
...jest.requireActual('../../services/chronikService'),
ChronikBlockchainClient: jest.fn(() => ({
getSubscribedAddresses: jest.fn(),
subscribeInitialAddresses: jest.fn()
}))
}
})

describe('getNullDataScriptData tests', () => {
it('Null for empty OP_RETURN', async () => {
const script = '6a' + ''
Expand Down Expand Up @@ -69,7 +79,7 @@ describe('getNullDataScriptData tests', () => {
key: 'value',
some: 'other'
},
rawMessage: "key=value some=other"
rawMessage: 'key=value some=other'
})
})
it('Dict with array', async () => {
Expand All @@ -81,7 +91,7 @@ describe('getNullDataScriptData tests', () => {
key: 'value',
some: ['value1', 'value2']
},
rawMessage: "key=value some=value1|value2"
rawMessage: 'key=value some=value1|value2'
})
})
it('Non-ASCII data', async () => {
Expand All @@ -93,7 +103,7 @@ describe('getNullDataScriptData tests', () => {
expect(data).toStrictEqual({
paymentId: '',
message: '😂👍©ĸðМжЪы% ŋæPßđĸł„»“æ}¹↓£³→²',
rawMessage: "😂👍©ĸðМжЪы% ŋæPßđĸł„»“æ}¹↓£³→²",
rawMessage: '😂👍©ĸðМжЪы% ŋæPßđĸł„»“æ}¹↓£³→²'
})
})
it('Non-ASCII data with paymentId', async () => {
Expand Down Expand Up @@ -123,7 +133,7 @@ describe('getNullDataScriptData tests', () => {
expect(data).toStrictEqual({
paymentId: '',
message: 'PQRSTUVW',
rawMessage: 'PQRSTUVW',
rawMessage: 'PQRSTUVW'
})
})
it('Ignore incomplete paymentId', async () => {
Expand All @@ -132,7 +142,7 @@ describe('getNullDataScriptData tests', () => {
expect(data).toStrictEqual({
paymentId: '',
message: 'PQRSTUVW',
rawMessage: 'PQRSTUVW',
rawMessage: 'PQRSTUVW'
})
})
})
18 changes: 14 additions & 4 deletions tests/unittests/transactionService.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import prisma from 'prisma/clientInstance'
import * as transactionService from 'services/transactionService'
import { prismaMock } from 'prisma/mockedClient'
import { mockedBCHAddress, mockedUSDPriceOnTransaction, mockedCADPriceOnTransaction, mockedTransaction, mockedUserProfile, mockedAddressIdList, mockedAddressesOnButtons, mockedTransactionList } from '../mockedObjects'
import { mockedBCHAddress, mockedUSDPriceOnTransaction, mockedCADPriceOnTransaction, mockedTransaction, mockedUserProfile, mockedAddressIdList, mockedTransactionList } from '../mockedObjects'
import { CacheSet } from 'redis/index'
import { Prisma } from '@prisma/client'
import * as addressService from 'services/addressService'
import { RESPONSE_MESSAGES } from 'constants/index'
import { RESPONSE_MESSAGES } from 'constants/index'

const includePrices = {
prices: {
Expand All @@ -25,6 +25,9 @@ describe('Create services', () => {
prismaMock.transaction.upsert.mockResolvedValue(mockedTransaction)
prisma.transaction.upsert = prismaMock.transaction.upsert

prismaMock.transaction.findUniqueOrThrow.mockResolvedValue(mockedTransaction)
prisma.transaction.findUniqueOrThrow = prismaMock.transaction.findUniqueOrThrow

prismaMock.transaction.findUnique.mockResolvedValue(mockedTransaction)
prisma.transaction.findUnique = prismaMock.transaction.findUnique

Expand Down Expand Up @@ -115,7 +118,7 @@ describe('Fetch transactions by paybuttonId', () => {
prismaMock.transaction.findMany.mockResolvedValue(mockedTransactionList)
prisma.transaction.findMany = prismaMock.transaction.findMany
prisma.addressesOnButtons.findMany = prismaMock.addressesOnButtons.findMany

jest.spyOn(addressService, 'fetchAddressesByPaybuttonId').mockImplementation(async (_: string) => {
return mockedAddressIdList
})
Expand All @@ -124,8 +127,16 @@ describe('Fetch transactions by paybuttonId', () => {
where: {
addressId: {
in: mockedAddressIdList
},
address: {
networkId: {
in: [1, 2]
}
}
},
orderBy: {
timestamp: 'asc'
},
include: includeAddressAndPrices
}

Expand All @@ -147,4 +158,3 @@ describe('Fetch transactions by paybuttonId', () => {
}
})
})

Loading
Loading