Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mockKV() to createKV() #74

Closed
kulla opened this issue Nov 27, 2020 · 0 comments · Fixed by #92
Closed

Change mockKV() to createKV() #74

kulla opened this issue Nov 27, 2020 · 0 comments · Fixed by #92

Comments

@kulla
Copy link
Member

kulla commented Nov 27, 2020

The current way to mock a KV store is

https://github.com/serlo/serlo.org-cloudflare-worker/blob/c96e71181f854840b335edb1118add87e3917042/__tests__/_helper.ts#L64-L77

The function adds a mock for the KV to the global namespace. With this approach we need a generic variable setting at https://github.com/serlo/serlo.org-cloudflare-worker/blob/c96e71181f854840b335edb1118add87e3917042/__tests__/_helper.ts#L67 and the line https://github.com/serlo/serlo.org-cloudflare-worker/blob/c96e71181f854840b335edb1118add87e3917042/__tests__/_helper.ts#L64 is a duplication of the definition at https://github.com/serlo/serlo.org-cloudflare-worker/blob/c96e71181f854840b335edb1118add87e3917042/src/kv.d.ts#L22-L28

A solution is to create a function createKV() at __tests__/__utils__/index.ts with the signature:

export function createKV<Keys extends string>(): KV<Keys> {
   ...
}

Then we can use this function in our test code with for example

global.PATH_INFO_KV = createKV()

See https://developers.cloudflare.com/workers/runtime-apis/kv for a doc what a KV store is.

@kulla kulla added this to Ideas in U serlo.org Maintenance via automation Nov 27, 2020
@kulla kulla added the good first issue Good for newcomers label Nov 28, 2020
@kulla kulla changed the title Change mockKV() to createMock() Change mockKV() to createKV() Nov 28, 2020
@kulla kulla linked a pull request Dec 3, 2020 that will close this issue
@kulla kulla closed this as completed in #92 Dec 3, 2020
U serlo.org Maintenance automation moved this from Ideas to Done Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant