Skip to content

Commit

Permalink
chore: remove http-server dep only used for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed Feb 7, 2025
1 parent e7ed44f commit e6a3e86
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 154 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@dcl/eslint-config": "^1.1.9",
"@types/form-data": "^2.5.0",
"@well-known-components/env-config-provider": "^1.1.1",
"@well-known-components/http-server": "^2.0.0",
"@well-known-components/interfaces": "^1.4.0",
"@well-known-components/logger": "^3.0.0",
"@well-known-components/test-helpers": "^1.5.3",
Expand Down
83 changes: 42 additions & 41 deletions test/ContentClient.E2E.spec.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import { createFetchComponent } from '@well-known-components/fetch-component'
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ContentClient, createContentClient } from '../src'
import { runServerBasedE2ETest } from './components'
import { multipartParserWrapper } from './utils'

runServerBasedE2ETest('test client post', ({ components }) => {
let client: ContentClient
// runServerBasedE2ETest('test client post', ({ components }) => {
// let client: ContentClient

it('configures some endpoints', () => {
components.router.get('/available-content', async (ctx) => {
const params = new URLSearchParams(ctx.url.search)
const cids = params.getAll('cid')

return {
status: 200,
body: cids.map(($) => ({
cid: $,
available: false
}))
}
})
// it('creates the client', async () => {
// client = createContentClient({
// url: await components.getBaseUrl(),
// fetcher: createFetchComponent()
// })
// })

components.router.post(
'/entities',
multipartParserWrapper(async (ctx) => {
expect(ctx.formData.fields).toHaveProperty('entityId')
expect(ctx.formData.fields.entityId.value).toEqual('QmENTITY')
expect(ctx.formData.files).toHaveProperty('QmA')
expect(ctx.formData.files).toHaveProperty('QmB')
// TODO: FOR SOME REASON the `deployEntity` _does not_ send the entity itself by default
// TODO: FOR SOME REASON the `deployEntity` _does not_ send the entity itself by default

return {
status: 200,
body: {
creationTimestamp: Date.now()
}
}
})
)
})
// it('publishes an entity', async () => {
// const files = new Map<string, Uint8Array>()
// files.set('QmA', new Uint8Array([111, 112, 113]))
// files.set('QmB', Buffer.from('asd', 'utf-8'))

// await client.deploy({ authChain: [], entityId: 'QmENTITY', files })
// })
// })

describe('test client post', () => {
let client: ContentClient
let mockFetch: jest.Mock

beforeEach(() => {
mockFetch = jest.fn()
const mockFetcher = { fetch: mockFetch }

it('creates the client', async () => {
client = await createContentClient({
url: await components.getBaseUrl(),
fetcher: createFetchComponent()
client = createContentClient({
url: 'http://fake-url.com',
fetcher: mockFetcher
})
})

it('publishes an entity', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
status: 200,
json: async () => [
{ cid: 'QmA', available: true },
{ cid: 'QmB', available: true }
]
})

const files = new Map<string, Uint8Array>()
files.set('QmA', new Uint8Array([111, 112, 113]))
files.set('QmB', Buffer.from('asd', 'utf-8'))

await client.deploy({ authChain: [], entityId: 'QmENTITY', files })

expect(mockFetch).toHaveBeenCalledTimes(2)
const [_checkAvailabilityCall, deployCall] = mockFetch.mock.calls
expect(deployCall[0]).toContain('/entities')
expect(deployCall[1].method).toBe('POST')
})
})
34 changes: 2 additions & 32 deletions test/components.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { createConfigComponent } from '@well-known-components/env-config-provider'
import { createServerComponent, Router } from '@well-known-components/http-server'
import { IConfigComponent, IHttpServerComponent, ILoggerComponent, Lifecycle } from '@well-known-components/interfaces'
import { IConfigComponent, ILoggerComponent, Lifecycle } from '@well-known-components/interfaces'
import { createLogComponent } from '@well-known-components/logger'
import { createRunner, defaultServerConfig } from '@well-known-components/test-helpers'
import * as util from 'util'

// Record of components
export type TestComponents = {
config: IConfigComponent
logs: ILoggerComponent
server: IHttpServerComponent<AppContext>
router: Router<AppContext>
getBaseUrl: () => Promise<string>
}

Expand All @@ -22,27 +18,7 @@ export type AppContext = {
// main entry point of the application, it's role is to wire components
// together (controllers, handlers) and ultimately start the components
// by calling startComponents
async function main({ components, startComponents }: Lifecycle.EntryPointParameters<TestComponents>) {
const globalContext: AppContext = { components }

components.server.setContext(globalContext)

components.server.use(async function logger(ctx, next) {
const headers: Record<string, string> = {}

for (const [header, value] of ctx.request.headers) {
headers[header] = value
}

console.log('Test server got request:\n', ctx.request.method, ctx.url.toString(), JSON.stringify(headers, null, 2))
const response = await next()
console.log('Test server will send response:\n' + util.inspect(response, false, 30))
return response
})

components.server.use(components.router.middleware())

// start server and other components
async function main({ components: _components, startComponents }: Lifecycle.EntryPointParameters<TestComponents>) {
await startComponents()
}

Expand All @@ -53,19 +29,13 @@ async function initComponents(): Promise<TestComponents> {

const config = createConfigComponent(defaultServerConfig())

const server = await createServerComponent<AppContext>({ logs, config }, {})

const router = new Router<AppContext>()

const getBaseUrl = async () => {
return `http://${await config.requireString('HTTP_SERVER_HOST')}:${await config.requireString('HTTP_SERVER_PORT')}`
}

return /*components*/ {
logs,
config,
server,
router,
getBaseUrl
}
}
Expand Down
83 changes: 3 additions & 80 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,6 @@
dependencies:
"@types/node" "*"

"@types/http-errors@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.1.tgz#20172f9578b225f6c7da63446f56d4ce108d5a65"
integrity sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
Expand Down Expand Up @@ -1531,20 +1526,6 @@
"@well-known-components/interfaces" "^1.4.1"
cross-fetch "^3.1.5"

"@well-known-components/http-server@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@well-known-components/http-server/-/http-server-2.0.0.tgz#85ec93080ae64f962782699db3eeecd597f59405"
integrity sha512-baDP0+MpgqTnKLFFXS41WBbg9QIGCXTEA7BHf6JqW1evrTW10MKEx+rgEvQQlhCA5oXxUdKOD+xNnR3GqzGw9w==
dependencies:
"@types/http-errors" "^2.0.1"
destroy "^1.2.0"
fp-future "^1.0.1"
http-errors "^2.0.0"
mitt "^3.0.0"
node-fetch "^2.6.9"
on-finished "^2.4.1"
path-to-regexp "^6.2.1"

"@well-known-components/interfaces@^1.4.0", "@well-known-components/interfaces@^1.4.1":
version "1.4.2"
resolved "https://registry.yarnpkg.com/@well-known-components/interfaces/-/interfaces-1.4.2.tgz#e37eb296280abfcab14f0608b3bdfc84d5a21929"
Expand Down Expand Up @@ -2088,21 +2069,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==

[email protected], dependency-graph@~0.11.0:
version "0.11.0"
resolved "https://registry.yarnpkg.com/dependency-graph/-/dependency-graph-0.11.0.tgz#ac0ce7ed68a54da22165a85e97a01d53f5eb2e27"
integrity sha512-JeMq7fEshyepOWDfcfHK06N3MhyPhz++vtqWhMT5O9A3K42rdsEDpfdVqjaqaAhsw6a+ZqeDvQVtD0hFHQWrzg==

destroy@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015"
integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==

detect-newline@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
Expand Down Expand Up @@ -2149,11 +2120,6 @@ dotenv@^16.0.1:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.477:
version "1.4.490"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.490.tgz#d99286f6e915667fa18ea4554def1aa60eb4d5f1"
Expand Down Expand Up @@ -2701,11 +2667,6 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

fp-future@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/fp-future/-/fp-future-1.0.1.tgz#72e6247814f7a706d84939e5f459c2d7ec42316f"
integrity sha512-2McmZH/KsZqlqHju9+Ox0FC7q7Knve4t6ZeKubbhAz1xpnD7hkCrP8TP5g5QbbD5bA5jBANbXf/ew4x1FjSUrw==

fs-extra@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
Expand Down Expand Up @@ -2924,17 +2885,6 @@ html-escaper@^2.0.0:
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453"
integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==

http-errors@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3"
integrity sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==
dependencies:
depd "2.0.0"
inherits "2.0.4"
setprototypeof "1.2.0"
statuses "2.0.1"
toidentifier "1.0.1"

http2-client@^1.2.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/http2-client/-/http2-client-1.3.5.tgz#20c9dc909e3cc98284dd20af2432c524086df181"
Expand Down Expand Up @@ -2984,7 +2934,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, [email protected]:
inherits@2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
Expand Down Expand Up @@ -3842,7 +3792,7 @@ minimatch@^6.1.6:
dependencies:
brace-expansion "^2.0.1"

mitt@^3.0.0, mitt@^3.0.1:
mitt@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1"
integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==
Expand Down Expand Up @@ -3898,7 +3848,7 @@ node-fetch-h2@^2.3.0:
dependencies:
http2-client "^1.2.5"

[email protected], node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.11, node-fetch@^2.6.7, node-fetch@^2.6.9:
[email protected], node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.11, node-fetch@^2.6.7:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
Expand Down Expand Up @@ -4000,13 +3950,6 @@ object.assign@^4.1.4:
has-symbols "^1.0.3"
object-keys "^1.1.1"

on-finished@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f"
integrity sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==
dependencies:
ee-first "1.1.1"

once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
Expand Down Expand Up @@ -4154,11 +4097,6 @@ path-parse@^1.0.7:
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==

path-to-regexp@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5"
integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==

path-to-regexp@^8.1.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-8.2.0.tgz#73990cc29e57a3ff2a0d914095156df5db79e8b4"
Expand Down Expand Up @@ -4369,11 +4307,6 @@ semver@^7.3.7, semver@^7.5.3:
dependencies:
lru-cache "^6.0.0"

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==

shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
Expand Down Expand Up @@ -4498,11 +4431,6 @@ stack-utils@^2.0.3:
dependencies:
escape-string-regexp "^2.0.0"

[email protected]:
version "2.0.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==

streamsearch@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
Expand Down Expand Up @@ -4663,11 +4591,6 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
Expand Down

0 comments on commit e6a3e86

Please sign in to comment.