Skip to content

Commit

Permalink
Merge pull request #2 from conejerock/FIX-generate-mode
Browse files Browse the repository at this point in the history
Added behavior for generation
  • Loading branch information
conejerock committed Jul 21, 2022
2 parents da2442a + eb8f523 commit 8ed4c7b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/icon.svg → docs/nuxt-unleash.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "nuxt-unleash",
"version": "1.0.3",
"version": "1.0.4",
"description": "Nuxt.js module to use Unleash toggle feature services",
"keywords": [
"nuxt",
Expand Down
2 changes: 1 addition & 1 deletion templates/plugin.ts
Expand Up @@ -14,7 +14,7 @@ const extractIP = ({ ssrContext, store }, headerIp) => {
return undefined;
}

if (process.server) {
if (process.server && ssrContext?.req?.socket?.remoteAddress) {
let ip = ssrContext.req.socket.remoteAddress;
if (headerIp) {
ip = ssrContext.req.headers[headerIp] || "";
Expand Down
9 changes: 9 additions & 0 deletions test/fixture/ok-generate/nuxt.config.js
@@ -0,0 +1,9 @@
export default {
rootDir: __dirname,
buildModules: ['../../../src/index.ts'],
unleash: {
url: 'http://some-url.com',
instanceId: 'SOME-KEY-PRODICTION',
environment: 'production'
}
}
15 changes: 15 additions & 0 deletions test/fixture/ok-generate/pages/App.vue
@@ -0,0 +1,15 @@
<template>
<h1>{{ value }}</h1>
</template>

<script>
export default {
asyncData (ctx) {
return {
value: ctx.app.unleash.exists('new-feature')
? 'New Feature Exists'
: 'New Feature Doesnt Exist'
}
}
}
</script>
23 changes: 23 additions & 0 deletions test/ok-generate.test.ts
@@ -0,0 +1,23 @@
import { setupTest, get } from '@nuxt/test-utils'

describe('ok', () => {
jest.mock('axios', () => ({
get: jest.fn(() => {
const singleFeature = require('./fixture/response/single-allow-by-ip-feature')
return Promise.resolve(singleFeature.default)
}),
create: jest.fn(() => {
return this
})
}))
setupTest({
server: true,
generate: true,
fixture: 'fixture/ok-generate'
})

test('should pass module with template instance', async () => {
const { body } = await get('/App')
expect(body).toContain('New Feature Doesnt Exist')
})
})

0 comments on commit 8ed4c7b

Please sign in to comment.