Skip to content

Commit

Permalink
test: 💍 Add test coverage with mocked GraphQL layer (pt2) (#4)
Browse files Browse the repository at this point in the history
* chore: 🤖 initial test structure with msw

* chore: 🤖 start application tests

* test: 💍 add get applications

* test: 💍 add create application

* test: 💍 add update application

* test: 💍 add delete application

* test: 💍 add get domains

* chore: 🤖 delete unused, create alias

* chore: 🤖 update mocks

* chore: 🤖 update gitignore

* chore: 🤖 update applications test

* chore: 🤖 format

* chore: 🤖 update Domains handler

* test: 💍 extend domains test by id and hostname

* test: 💍 test domains by zone id

* test: 💍 create domain

* test: 💍 delete domain

* test: 💍 verify domain

* test: 💍 list zones

* test: 💍 get zone

* test: 💍 create zone for private gateway

* test: 💍 delete zone

* test: 💍 create ens record

* test: 💍 get ens record

* test: 💍 get ens record by name

* test: 💍 verify ens record

* test: 💍 delete ens record

* test: 💍 list ens records

* test: 💍 list by ipns record id

* test: 💍 get fleek functions by name

* test: 💍 get fleek functions

* test: 💍 create fleek functions

* test: 💍 delete fleek function

* test: 💍 add file to ipfs

* test: 💍 add files to ipfs

* test: 💍 todo should add files by path

* chore: 🤖 format

* fix: 🐛 conflict  amend

* refactor: 💡 generate cids texts

* chore: 🤖 remove graphql schema

* chore: 🤖 add TODO

* chore: 🤖 remove tester package

* test: 💍 add publish ipns name

* test: 💍 publish ipns record

* test: 💍 create ipns record

* test: 💍 create ipns record for site

* test: 💍 delete ipns record

* test: 💍 list ipns record

* test: 💍 get ipns record by name

* test: 💍 get private gateway

* test: 💍 get private gatewa by slug

* test: 💍 get private gateways

* test: 💍 create private gateways

* test: 💍 delete private gateway

* test: 💍 update private gateway

* test: 💍 create project

* test: 💍 get project

* test: 💍 get projects

* test: 💍 get site by id

* test: 💍 get site by slug

* test: 💍 list sites

* test: 💍 create site

* test: 💍 delete site

* test: 💍 create custom ipfs deployment

* test: 💍 get deployment by id

* test: 💍 get personal access tokens

* test: 💍 delete personal access tokens

* fix: 🐛 conflict  amend
  • Loading branch information
heldrida authored Oct 25, 2024
1 parent 4b6e28c commit e667f10
Show file tree
Hide file tree
Showing 17 changed files with 2,207 additions and 0 deletions.
179 changes: 179 additions & 0 deletions src/clients/ipns.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { describe, expect, it, afterAll, afterEach, beforeAll } from 'vitest';
import { server } from '../mocks/graphql/node';
import { mockGraphqlServiceApiUrl as graphqlServiceApiUrl } from '../mocks/graphql/handlers';
import { FleekSdk } from '../FleekSdk';
import state from '../mocks/state';

const TEST_KEY =
'k51qzi5uqu5djd7wik4gj3evcbnx2okerdrh0swusu07mu2ak1v1r3y70e7k8o';
const TEST_INPUT =
'CjQvaXBmcy9RbVBxckVISlRleDJDUGJxTlVMQ21iU0ZKVDNib0J3QUFmTWI1VWp2WHRLakVlEkB/s3F4iHVMyA9LOFizt5N4PHiI2APD15wsMa1RXGwmugThVpUjTw+5HHwFt16TI/8AKk/1p8+26hylxMxd3wAIGAAiHjIwMjMtMDgtMDVUMDk6NDk6MjguNDk5MDAwMDAwWigNMODyh77rhc0FQkCdgM1u1AAUsdf4pE7/kNYjl438/g6Ja48Tr2evFSRc6YSMgljaKX8PpQC0JDlZqF2jiKdHRUOaxLHArPo9MW0PSosBpWNUVEwbAAs0LrfB+WBlVmFsdWVYNC9pcGZzL1FtUHFyRUhKVGV4MkNQYnFOVUxDbWJTRkpUM2JvQndBQWZNYjVVanZYdEtqRWVoU2VxdWVuY2UNaFZhbGlkaXR5WB4yMDIzLTA4LTA1VDA5OjQ5OjI4LjQ5OTAwMDAwMFpsVmFsaWRpdHlUeXBlAA==';

describe('IPNS', () => {
const sdk = new FleekSdk({
graphqlServiceApiUrl,
accessTokenService: {} as any,
});

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it('should publish IPNS name', async () => {
const response = await sdk.ipns().publishSignedName({
input: TEST_INPUT,
key: TEST_KEY,
});

expect(response).toMatchInlineSnapshot(
'"k51qzi5uqu5dgsc1bvsuk1x84bptdvp8cupbnnbqxpxzd629gadpci3kpcm311"',
);
});

// TODO: Mocking is failing for w3name
// for some reason
it.todo('should get resolved IPNS name', async (context) => {
const response = await sdk.ipns().resolveName({ name: TEST_KEY });

expect(response).toMatchInlineSnapshot(
'"/ipfs/QmRG4xcsmoZuXqKuPz3uVBgvo3GZ6k1kLZWhmvzuKtDr9s"',
);
});

it('should publish IPNS record', async () => {
const response = await sdk.ipns().publishRecord({
id: state.ipns.ipnsRecord.electronicCoEshop.id,
hash: 'QmRG4xcsmoZuXqKuPz3uVBgvo3GZ6k1kLZWhmvzuKtDr9s',
});

expect(response).toMatchInlineSnapshot(`
Object {
"ensRecords": Array [
Object {
"id": "8d3ad502-ec4d-489e-858e-d112656f3511",
},
Object {
"id": "clm0mhccs000108ma34jn6ed3",
},
],
"hash": "QmRG4xcsmoZuXqKuPz3uVBgvo3GZ6k1kLZWhmvzuKtDr9s",
"id": "clgkj995t000108med7gb2w4v",
"name": "k51qzi5uqu5dhrupvn0ru1c6el43rhimh95cuiwqy0ofo8bgomvq296b49v9r7",
}
`);
});

it('should create IPNS record', async () => {
const response = await sdk.ipns().createRecord();

expect(response).toMatchInlineSnapshot(
{ id: expect.any(String) },
`
Object {
"ensRecords": Array [],
"hash": null,
"id": Any<String>,
"name": "test-name",
}
`,
);
});

it('should create IPNS record for site', async () => {
const response = await sdk
.ipns()
.createRecordForSite({ siteId: state.sites.site.electronicCoEshop.id });

// TODO: Investigate why the hash changed here
expect(response).toMatchInlineSnapshot(
{ id: expect.any(String) },
`
Object {
"ensRecords": Array [],
"hash": "bafybeibtme5hmkjxsryerf6pihhfbhifwnsz7gmhnfqglg2r326m4glzva",
"id": Any<String>,
"name": "test-name",
}
`,
);
});

it('should delete IPNS record', async () => {
const response = await sdk
.ipns()
.deleteRecord({ id: state.ipns.ipnsRecord.electronicCoEshop.id });

expect(response).toMatchInlineSnapshot(`
Object {
"ensRecords": Array [],
"hash": "QmcvfRw5WDutRzvRNq2matcJWW2nKWFGDbqxaaTxnWksME",
"id": "clgkj995t000108med7gb2w4v",
"name": "k51qzi5uqu5dhrupvn0ru1c6el43rhimh95cuiwqy0ofo8bgomvq296b49v9r7",
}
`);
});

it('should list IPNS records', async () => {
const response = await sdk.ipns().listRecords();

expect(response).toMatchInlineSnapshot(`
Array [
Object {
"ensRecords": Array [
Object {
"id": "8d3ad502-ec4d-489e-858e-d112656f3511",
},
Object {
"id": "clm0mhccs000108ma34jn6ed3",
},
],
"hash": "QmcvfRw5WDutRzvRNq2matcJWW2nKWFGDbqxaaTxnWksME",
"id": "clgkj995t000108med7gb2w4v",
"name": "k51qzi5uqu5dhrupvn0ru1c6el43rhimh95cuiwqy0ofo8bgomvq296b49v9r7",
},
Object {
"ensRecords": Array [
Object {
"id": "40767ba9-eb85-439b-9369-489459a9376b",
},
],
"hash": "QmX7WyiLtbvmfbUzN2eJuvmDuGZSDjavuauwaJL4bFC5SJ",
"id": "clgkj9ipf000208me9yzre1cn",
"name": "k51qzi5uqu5dh2c8ec00yowiapopchxdvnwh6iy2xoxc51inldruqh4yvzgez5",
},
Object {
"ensRecords": Array [
Object {
"id": "af470cc1-08d8-4d39-be6f-b0eebc0a6480",
},
],
"hash": "QmW73w6jvat7zDpFkYHft8eB88LiU6fPyV9LUX9et7XRUy",
"id": "clgkj9pfa000308meh73d8nff",
"name": "k51qzi5uqu5dipwqop5kj5na30qlwqbyyn54g8y3jcm3sdc02t9tjlec2a46ci",
},
]
`);
});

it('should get IPNS record by name', async () => {
const response = await sdk
.ipns()
.getRecord({ name: state.ipns.ipnsRecord.electronicCoEshop.name });

expect(response).toMatchInlineSnapshot(`
Object {
"ensRecords": Array [
Object {
"id": "8d3ad502-ec4d-489e-858e-d112656f3511",
},
Object {
"id": "clm0mhccs000108ma34jn6ed3",
},
],
"hash": "QmcvfRw5WDutRzvRNq2matcJWW2nKWFGDbqxaaTxnWksME",
"id": "clgkj995t000108med7gb2w4v",
"name": "k51qzi5uqu5dhrupvn0ru1c6el43rhimh95cuiwqy0ofo8bgomvq296b49v9r7",
}
`);
});
});
7 changes: 7 additions & 0 deletions src/clients/ipns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class IpnsClient {

public publishSignedName = async ({ key, input }: PublishSignedNameArgs) => {
const response = await this.graphqlClient.mutation({
__name: 'PublishSignedIpnsName',
publishSignedIpnsName: {
__args: {
data: {
Expand Down Expand Up @@ -89,6 +90,7 @@ export class IpnsClient {
id,
}: PublishRecordArgs): Promise<IpnsRecord> => {
const response = await this.graphqlClient.mutation({
__name: 'PublishIpnsRecord',
publishIpnsRecord: {
__args: {
where: {
Expand All @@ -107,6 +109,7 @@ export class IpnsClient {

public createRecord = async (): Promise<IpnsRecord> => {
const response = await this.graphqlClient.mutation({
__name: 'CreateIpnsRecord',
createIpnsRecord: IpnsClient.RECORD_MAPPED_PROPERTIES,
});

Expand All @@ -117,6 +120,7 @@ export class IpnsClient {
siteId,
}: CreateRecordForSiteArgs): Promise<IpnsRecord> => {
const response = await this.graphqlClient.mutation({
__name: 'CreateIpnsRecordForSite',
createIpnsRecordForSite: {
__args: {
where: {
Expand All @@ -134,6 +138,7 @@ export class IpnsClient {
id,
}: DeleteRecordArgs): Promise<IpnsRecord> => {
const response = await this.graphqlClient.mutation({
__name: 'DeleteIpnsRecord',
deleteIpnsRecord: {
__args: {
where: {
Expand All @@ -149,6 +154,7 @@ export class IpnsClient {

public listRecords = async (): Promise<IpnsRecord[]> => {
const response = await this.graphqlClient.query({
__name: 'GetIpnsRecords',
ipnsRecords: { data: IpnsClient.RECORD_MAPPED_PROPERTIES },
});

Expand All @@ -157,6 +163,7 @@ export class IpnsClient {

public getRecord = async ({ name }: GetRecordArgs): Promise<IpnsRecord> => {
const response = await this.graphqlClient.query({
__name: 'GetIpnsRecordByName',
ipnsRecord: {
__args: {
where: {
Expand Down
Loading

0 comments on commit e667f10

Please sign in to comment.