-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 💍 Add test coverage with mocked GraphQL layer (initial) (#3)
* 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
- Loading branch information
Showing
30 changed files
with
6,165 additions
and
2,256 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 |
---|---|---|
|
@@ -63,3 +63,6 @@ schema.graphql | |
|
||
# Local | ||
.local | ||
|
||
# Pnpm | ||
.pnpm-store |
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,27 @@ | ||
import { CID } from 'multiformats/cid'; | ||
import { sha256 } from 'multiformats/hashes/sha2'; | ||
|
||
async function textToCidV0(text: string): Promise<string> { | ||
const textEncoder = new TextEncoder(); | ||
const bytes = textEncoder.encode(text); | ||
|
||
const hash = await sha256.digest(bytes); | ||
|
||
const cid = CID.createV0(hash); | ||
|
||
return cid.toString(); | ||
} | ||
|
||
const text = process.argv[2]; | ||
|
||
if (!text) { | ||
console.error('👹 Oops! Please provide some text/content'); | ||
process.exit(1); | ||
} | ||
|
||
textToCidV0(text).then(cidString => { | ||
console.log('✅ CIDv0:', cidString); | ||
}).catch(error => { | ||
console.error('👹 Oops! found error:', error); | ||
process.exit(1); | ||
}); |
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
Large diffs are not rendered by default.
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 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,204 @@ | ||
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'; | ||
|
||
describe('Applications', () => { | ||
const sdk = new FleekSdk({ | ||
graphqlServiceApiUrl, | ||
accessTokenService: {} as any, | ||
}); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
it('should get application', async () => { | ||
const response = await sdk.applications().get({ | ||
id: state.auth.application.electronicCoMobileApp.id, | ||
}); | ||
|
||
expect(response).toMatchInlineSnapshot(` | ||
Object { | ||
"clientId": "client_SCmayempJ1d953yjn1yx", | ||
"createdAt": "2023-03-23T12:05:13.641Z", | ||
"id": "cli2ymypd000208l86gjd6p17", | ||
"name": "electronicCoMobileApp", | ||
"updatedAt": "2023-03-23T12:05:13.641Z", | ||
"whiteLabelDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "clu2xf6uz000208jv6qskg1hm", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "clu2xd1bs000108jv0v0d2xmy", | ||
}, | ||
], | ||
"whitelistDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "cli2z1zim000008l66z4l7qg3", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "cli2z10wq000208jw42gd4pyh", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('should list applications', async () => { | ||
const response = await sdk.applications().list(); | ||
|
||
expect(response).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"clientId": "client_ZRacrn3b1ForrjK5u8VD", | ||
"createdAt": "2023-03-23T11:05:13.641Z", | ||
"id": "cli2ymucu000108l81grqhzcp", | ||
"name": "electronicCoWebApp", | ||
"updatedAt": "2023-03-23T11:05:13.641Z", | ||
"whiteLabelDomains": Array [], | ||
"whitelistDomains": Array [], | ||
}, | ||
Object { | ||
"clientId": "client_SCmayempJ1d953yjn1yx", | ||
"createdAt": "2023-03-23T12:05:13.641Z", | ||
"id": "cli2ymypd000208l86gjd6p17", | ||
"name": "electronicCoMobileApp", | ||
"updatedAt": "2023-03-23T12:05:13.641Z", | ||
"whiteLabelDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "clu2xf6uz000208jv6qskg1hm", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "clu2xd1bs000108jv0v0d2xmy", | ||
}, | ||
], | ||
"whitelistDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "cli2z1zim000008l66z4l7qg3", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "cli2z10wq000208jw42gd4pyh", | ||
}, | ||
], | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
it('should create application', async () => { | ||
const response = await sdk.applications().create({ | ||
name: 'test-application', | ||
whitelistDomains: ['fleek.xyz'], | ||
}); | ||
|
||
// TODO: This mandates returning whitelistDomains | ||
// and whiteLabelDomains, while the non-schema version | ||
// does not requires it for some reason. | ||
// Do a test in runtime to check | ||
// see handler | ||
expect(response).toMatchInlineSnapshot( | ||
{ | ||
createdAt: expect.anything(), | ||
id: expect.any(String), | ||
updatedAt: expect.anything(), | ||
}, | ||
` | ||
Object { | ||
"clientId": "client_testtesttest", | ||
"createdAt": Anything, | ||
"id": Any<String>, | ||
"name": "test-application", | ||
"updatedAt": Anything, | ||
"whiteLabelDomains": Array [], | ||
"whitelistDomains": Array [], | ||
} | ||
`, | ||
); | ||
}); | ||
|
||
it('should update application', async () => { | ||
const response = await sdk.applications().update({ | ||
id: state.auth.application.electronicCoMobileApp.id, | ||
name: 'new-mobile-app-name', | ||
}); | ||
|
||
expect(response).toMatchInlineSnapshot( | ||
{ updatedAt: expect.anything() }, | ||
` | ||
Object { | ||
"clientId": "client_SCmayempJ1d953yjn1yx", | ||
"createdAt": "2023-03-23T12:05:13.641Z", | ||
"id": "cli2ymypd000208l86gjd6p17", | ||
"name": "new-mobile-app-name", | ||
"updatedAt": Anything, | ||
"whiteLabelDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "clu2xf6uz000208jv6qskg1hm", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "clu2xd1bs000108jv0v0d2xmy", | ||
}, | ||
], | ||
"whitelistDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "cli2z1zim000008l66z4l7qg3", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "cli2z10wq000208jw42gd4pyh", | ||
}, | ||
], | ||
} | ||
`, | ||
); | ||
}); | ||
|
||
it('should delete application', async () => { | ||
const response = await sdk.applications().delete({ | ||
id: state.auth.application.electronicCoMobileApp.id, | ||
}); | ||
|
||
expect(response).toMatchInlineSnapshot(` | ||
Object { | ||
"clientId": "client_SCmayempJ1d953yjn1yx", | ||
"createdAt": "2023-03-23T12:05:13.641Z", | ||
"id": "cli2ymypd000208l86gjd6p17", | ||
"name": "electronicCoMobileApp", | ||
"updatedAt": "2023-03-23T12:05:13.641Z", | ||
"whiteLabelDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "clu2xf6uz000208jv6qskg1hm", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "clu2xd1bs000108jv0v0d2xmy", | ||
}, | ||
], | ||
"whitelistDomains": Array [ | ||
Object { | ||
"hostname": "app.best-electronic.co", | ||
"id": "cli2z1zim000008l66z4l7qg3", | ||
}, | ||
Object { | ||
"hostname": "app.electronic.co", | ||
"id": "cli2z10wq000208jw42gd4pyh", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.