Skip to content

Commit

Permalink
fix(backend): fix OP resource tests (#2969)
Browse files Browse the repository at this point in the history
* feat(backend): create operator kratos identity on backend startup

* chore: formatting

* Add migration files

* Update migration files

* Fix file name for migrations

* feat(auth): create basic tenant service and model plus graphql schema

* feat(auth): add basic tenant schema and appropriate resources like model and service

* feat(backend): add apollo client do dependencies

* feat(auth): delete tenant

* chore(auth): format

* feat(backend): create tenant service implementation

* feat(packages): make multi tenant work wip

* feat(backend): update resolvers with tenant id and finish the tenant creation

* feat(backend): small changes to schema + mapping of tenant to graphql + bruno

* fix: outgoing/quote tests

* fix: combined payments tests

* chore: formatting

* fix: update tenant id requirements for some services

* chore: fix rebase issues

* chore: try to fix apollo errors in ilp payment method tests

---------

Co-authored-by: bsanduc <[email protected]>
Co-authored-by: golobitch <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent 3ab716c commit 7bcb13a
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 327 deletions.
4 changes: 2 additions & 2 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,42 +105,6 @@ export function initIocContainer(
}
)

container.singleton(
'tenantService',
async (deps: IocContract<AppServices>) => {
const [logger, knex] = await Promise.all([
deps.use('logger'),
deps.use('knex')
])

return createTenantService({ logger, knex })
}
)

container.singleton(
'tenantService',
async (deps: IocContract<AppServices>) => {
const [logger, knex] = await Promise.all([
deps.use('logger'),
deps.use('knex')
])

return createTenantService({ logger, knex })
}
)

container.singleton(
'tenantService',
async (deps: IocContract<AppServices>) => {
const [logger, knex] = await Promise.all([
deps.use('logger'),
deps.use('knex')
])

return createTenantService({ logger, knex })
}
)

container.singleton(
'accessService',
async (deps: IocContract<AppServices>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ exports.up = function (knex) {
table.uuid('tenantId').notNullable()
table.foreign('tenantId').references('id').inTable('tenants')
})
.table('grants', function (table) {
table.uuid('tenantId').notNullable()
table.foreign('tenantId').references('id').inTable('tenants')
})
}

/**
Expand All @@ -48,8 +44,4 @@ exports.down = function (knex) {
table.dropForeign(['tenantId'])
table.dropColumn('tenantId')
})
.table('grants', function (table) {
table.dropForeign(['tenantId'])
table.dropColumn('tenantId')
})
}
32 changes: 16 additions & 16 deletions packages/backend/src/graphql/generated/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/backend/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ describe('OutgoingPayment Resolvers', (): void => {

const input = {
walletAddressId: payment.walletAddressId,
tenantId,
incomingPayment: mockIncomingPaymentUrl,
debitAmount: {
value: BigInt(56),
Expand Down Expand Up @@ -781,6 +782,7 @@ describe('OutgoingPayment Resolvers', (): void => {

const input = {
walletAddressId: uuid(),
tenantId,
incomingPayment: mockIncomingPaymentUrl,
debitAmount: {
value: BigInt(56),
Expand Down Expand Up @@ -832,6 +834,7 @@ describe('OutgoingPayment Resolvers', (): void => {

const input = {
walletAddressId: uuid(),
tenantId,
incomingPayment: mockIncomingPaymentUrl,
debitAmount: {
value: BigInt(56),
Expand Down
3 changes: 0 additions & 3 deletions packages/backend/src/graphql/resolvers/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ describe('Quote Resolvers', (): void => {
): Promise<QuoteModel> => {
return await createQuote(deps, {
walletAddressId,
tenantId,
receiver,
debitAmount: {
value: BigInt(56),
Expand Down Expand Up @@ -195,7 +194,6 @@ describe('Quote Resolvers', (): void => {
}
input = {
walletAddressId: uuid(),
tenantId: uuid(),
receiver,
debitAmount
}
Expand All @@ -217,7 +215,6 @@ describe('Quote Resolvers', (): void => {
)
const input = {
walletAddressId,
tenantId,
debitAmount: amount,
receiveAmount,
receiver
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/graphql/resolvers/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const createQuote: MutationResolvers<ApolloContext>['createQuote'] =
const quoteService = await ctx.container.use('quoteService')
const options: CreateQuoteOptions = {
walletAddressId: args.input.walletAddressId,
tenantId: args.input.tenantId,
receiver: args.input.receiver,
method: 'ilp'
}
Expand Down
44 changes: 0 additions & 44 deletions packages/backend/src/graphql/resolvers/tenant_endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { ApolloContext } from '../../app'
import { Pagination, SortOrder } from '../../shared/baseModel'
import { getPageInfo } from '../../shared/pagination'
import { EndpointType, TenantEndpoint } from '../../tenant/endpoints/model'
import {
ResolversTypes,
TenantResolvers,
TenantEndpoint as SchemaTenantEndpoint,
TenantEndpointType
} from '../generated/graphql'
Expand All @@ -14,45 +9,6 @@ export const mapTenantEndpointTypeToModelEndpointType = {
[EndpointType.WebhookBaseUrl]: TenantEndpointType.WebhookBaseUrl
}

export const getTenantEndpoints: TenantResolvers<ApolloContext>['endpoints'] =
async (
parent,
args,
ctx
): Promise<ResolversTypes['TenantEndpointsConnection']> => {
if (!parent.id) {
throw new Error('missing tenant id')
}
const tenantEndpointService = await ctx.container.use(
'tenantEndpointService'
)

const { sortOrder, ...pagination } = args
const order = sortOrder === 'ASC' ? SortOrder.Asc : SortOrder.Desc

const tenantEndpoints = await tenantEndpointService.getPage(
parent.id,
pagination,
order
)

console.log('TENANT ENDPOINTS: ', tenantEndpoints)

const pageInfo = await getPageInfo({
getPage: (pagination_?: Pagination, sortOrder_?: SortOrder) =>
tenantEndpointService.getPage(parent.id!, pagination_, sortOrder_),
page: tenantEndpoints
})

return {
pageInfo,
edges: tenantEndpoints.map((endpoint: TenantEndpoint) => ({
cursor: `${endpoint.tenantId}${endpoint.type}`,
node: tenantEndpointToGraphql(endpoint)
}))
}
}

export function tenantEndpointToGraphql(
tenantEndpoint: TenantEndpoint
): SchemaTenantEndpoint {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,6 @@ input CreateQuoteInput {
receiver: String!
"Unique key to ensure duplicate or retried requests are processed only once. See [idempotence](https://en.wikipedia.org/wiki/Idempotence)"
idempotencyKey: String
"ID of the tenant"
tenantId: ID!
}

type QuoteResponse {
Expand Down Expand Up @@ -1110,6 +1108,8 @@ input CreateOutgoingPaymentFromIncomingPaymentInput {
metadata: JSONObject
"Unique key to ensure duplicate or retried requests are processed only once. See [idempotence](https://en.wikipedia.org/wiki/Idempotence)"
idempotencyKey: String
"ID of a tenant"
tenantId: ID!
}

input CreateIncomingPaymentInput {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/open_payments/grant/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class Grant extends BaseModel {
public managementId!: string
public accessType!: AccessType
public accessActions!: AccessAction[]
public tenantId!: string
public expiresAt?: Date | null
public deletedAt?: Date

Expand Down
Loading

0 comments on commit 7bcb13a

Please sign in to comment.