generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Integration tests * fix: Update env vars in the gh workflow * Update test/integration/picks-controller.spec.ts Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com> Signed-off-by: Kevin Szuchet <31735779+kevinszuchet@users.noreply.github.com> * Update test/integration/picks-controller.spec.ts Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com> Signed-off-by: Kevin Szuchet <31735779+kevinszuchet@users.noreply.github.com> * chore: Remove log * refactor: Split config files and commands for unit and integrations testing * fix: Move the init schema script to the root * fix: Invalid volume without the ./ prefix * fix: Use pwd instead of relative path * fix: Use github workspace for the absolute path * fix: Try with a SQL file instead of sh init schema * fix: Try without the init script * chore: Trying with a select 1 * chore: Try changing the entrypoint * fix: Remove postgress in the end of the entrypoint * fix: Add quotes to the entrypoint command * fix: Assign permissions to the whole dir * fix: Try with the chown * chore: Echoing something in the entrypoint * chore: Trying with usr local bin * chore: Still trying * chore: Still trying * chore: Still trying * chore: Still trying * chore: Still trying * chore: Still trying * chore: Still trying * chore: Move script to test/db and mount the dir as volume * fix: Change owner to the workspace before checkout * feat: Add integration test step to the workflow * fix: Use correct config files paths * fix: Specify ports mapping * chore: Add logs in the init script for more verbosity * chore: Remove echos * chore: Try using a SQL script instead * fix: Remove postgres data volume from workflow * fix: Remove specific chown * fix: Try to manually start postgres with compose * chore: Always run stop containers * feat: Add run in band option to run integration tests sequentially * styles: Init schema EOF --------- Signed-off-by: Kevin Szuchet <31735779+kevinszuchet@users.noreply.github.com> Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>
- Loading branch information
1 parent
0777551
commit 773b97a
Showing
13 changed files
with
222 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
HTTP_SERVER_HOST=localhost | ||
|
||
PG_COMPONENT_PSQL_DATABASE=marketplace | ||
PG_COMPONENT_PSQL_CONNECTION_STRING=postgres://testuser:testpassword@localhost:5432/marketplace | ||
PG_COMPONENT_PSQL_SCHEMA=favorites | ||
PG_COMPONENT_PSQL_PORT=5432 | ||
PG_COMPONENT_PSQL_HOST=localhost | ||
|
||
COLLECTIONS_SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/decentraland/collections-matic-mumbai | ||
|
||
SNAPSHOT_URL=https://score.snapshot.org/ | ||
SNAPSHOT_NETWORK=5 | ||
SNAPSHOT_SPACE=1emu.eth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Utilitarian compose file to locally run postgres service | ||
# for integration testing purposes. | ||
|
||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
image: postgres | ||
restart: always | ||
environment: | ||
- POSTGRES_USER=admin | ||
- POSTGRES_PASSWORD=password | ||
- POSTGRES_DB=marketplace | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
- ./test/db/init-schema.sh:/docker-entrypoint-initdb.d/init-schema.sh | ||
|
||
volumes: | ||
postgres_data: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"moduleFileExtensions": ["ts", "js"], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
"coverageDirectory": "coverage", | ||
"collectCoverageFrom": ["src/**/*.ts", "src/**/*.js"], | ||
"coveragePathIgnorePatterns": ["/node_modules/", "index.ts", "src/migrations"], | ||
"testMatch": ["**/test/unit/*.spec.(ts)"], | ||
"testEnvironment": "node", | ||
"resetMocks": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"moduleFileExtensions": ["ts", "js"], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
"testMatch": ["**/test/integration/*.spec.(ts)"], | ||
"testEnvironment": "node", | ||
"resetMocks": true, | ||
"setupFilesAfterEnv": ["./jest.setup.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import nock from 'nock' | ||
|
||
nock.disableNetConnect() | ||
|
||
// Allow localhost connections so we can test local routes and mock servers. | ||
nock.enableNetConnect('127.0.0.1|localhost') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE SCHEMA favorites; | ||
-- CREATE THE ROLE AND ASSIGN IT TO THE PREVIOUSLY CREATED DB | ||
CREATE ROLE testuser WITH LOGIN PASSWORD 'testpassword'; | ||
GRANT ALL PRIVILEGES ON SCHEMA favorites TO testuser; | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA favorites; | ||
EOSQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import nock from 'nock' | ||
import { TPick } from '../../src/adapters/picks' | ||
import { DEFAULT_LIST_ID } from '../../src/migrations/1678303321034_default-list' | ||
import { HTTPResponse } from '../../src/types' | ||
import { test } from '../components' | ||
|
||
test('picks controller', function ({ components }) { | ||
beforeAll(async () => { | ||
const { config } = components | ||
|
||
const collectionsSubgraphUrl = await config.requireString('COLLECTIONS_SUBGRAPH_URL') | ||
const snapshotUrl = await config.requireString('SNAPSHOT_URL') | ||
|
||
nock(collectionsSubgraphUrl) | ||
.post(/.*/) | ||
.reply(200, { ok: true, data: { items: [{}] } }) | ||
|
||
nock(snapshotUrl) | ||
.post(/.*/) | ||
.reply(200, { result: { vp: 1 } }) | ||
}) | ||
|
||
beforeEach(async () => { | ||
await components.pg.query('TRUNCATE TABLE favorites.picks') | ||
}) | ||
|
||
describe('when making a request to GET /v1/picks/:itemId', () => { | ||
let itemId: string | ||
let userAddress: string | ||
let expectedResponse: HTTPResponse<Pick<TPick, 'userAddress'>>['body'] | ||
|
||
beforeEach(() => { | ||
itemId = '0x08de0de733cc11081d43569b809c00e6ddf314fb-0' | ||
userAddress = '0x1dec5f50cb1467f505bb3ddfd408805114406b10' | ||
}) | ||
|
||
describe('and there are no picks in the db', () => { | ||
beforeEach(() => { | ||
expectedResponse = { | ||
ok: true, | ||
data: { limit: 100, page: 0, pages: 0, results: [], total: 0 } | ||
} | ||
}) | ||
|
||
it('responds with an empty array of picks for the given item id', async () => { | ||
const { localFetch } = components | ||
const response = await localFetch.fetch(`/v1/picks/${itemId}`) | ||
|
||
expect(response.status).toEqual(200) | ||
expect(await response.json()).toEqual(expectedResponse) | ||
}) | ||
}) | ||
|
||
describe('and there are some picks in the db', () => { | ||
beforeEach(async () => { | ||
const { lists } = components | ||
|
||
await lists.addPickToList(DEFAULT_LIST_ID, itemId, userAddress) | ||
|
||
expectedResponse = { | ||
ok: true, | ||
data: { limit: 100, page: 0, pages: 1, results: [{ userAddress }], total: 1 } | ||
} | ||
}) | ||
|
||
it('responds with the an array with the recently created pick for the given item id', async () => { | ||
const { localFetch } = components | ||
const response = await localFetch.fetch(`/v1/picks/${itemId}`) | ||
|
||
expect(response.status).toEqual(200) | ||
expect(await response.json()).toEqual(expectedResponse) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters