1
1
'use strict'
2
2
const { describe, it, before, beforeEach, after } = require ( 'mocha' )
3
- const { expect } = require ( 'chai' )
3
+ const { expect, assert } = require ( 'chai' )
4
4
const { URL } = require ( 'url' ) // URL implementation with support for .origin attribute
5
5
const browser = require ( 'sinon-chrome' )
6
6
const { initState } = require ( '../../../add-on/src/lib/state' )
7
7
const { createRuntimeChecks } = require ( '../../../add-on/src/lib/runtime-checks' )
8
8
const { createRequestModifier } = require ( '../../../add-on/src/lib/ipfs-request' )
9
- const createDnslinkResolver = require ( '../../../add-on/src/lib/dnslink' )
9
+ const createDNSLinkResolver = require ( '../../../add-on/src/lib/dnslink' )
10
10
const { createIpfsPathValidator } = require ( '../../../add-on/src/lib/ipfs-path' )
11
11
const { optionDefaults } = require ( '../../../add-on/src/lib/options' )
12
12
@@ -33,7 +33,7 @@ describe('modifyRequest processing', function () {
33
33
state = initState ( optionDefaults )
34
34
getState = ( ) => state
35
35
const getIpfs = ( ) => { }
36
- dnslinkResolver = createDnslinkResolver ( getState )
36
+ dnslinkResolver = createDNSLinkResolver ( getState )
37
37
runtime = Object . assign ( { } , await createRuntimeChecks ( browser ) ) // make it mutable for tests
38
38
ipfsPathValidator = createIpfsPathValidator ( getState , getIpfs , dnslinkResolver )
39
39
modifyRequest = createRequestModifier ( getState , dnslinkResolver , ipfsPathValidator , runtime )
@@ -159,6 +159,30 @@ describe('modifyRequest processing', function () {
159
159
} )
160
160
} )
161
161
162
+ // We've moved blog to blog.ipfs.io but links to ipfs.io/blog/*
163
+ // are still around due to the way Discourse integration was done for comments.
164
+ // https://github.com/ipfs/blog/issues/360
165
+ describe ( 'a failed main_frame request to /ipns/ipfs.io/blog' , function ( ) {
166
+ it ( 'should be updated to /ipns/blog.ipfs.io' , async function ( ) {
167
+ const brokenDNSLinkUrl = 'http://example.com/ipns/ipfs.io/blog/some-post'
168
+ const fixedDNSLinkUrl = 'http://example.com/ipns/blog.ipfs.io/some-post'
169
+ // ensure clean modifyRequest
170
+ runtime = Object . assign ( { } , await createRuntimeChecks ( browser ) ) // make it mutable for tests
171
+ modifyRequest = createRequestModifier ( getState , dnslinkResolver , ipfsPathValidator , runtime )
172
+ // test
173
+ const request = {
174
+ statusCode : 404 ,
175
+ type : 'main_frame' ,
176
+ url : brokenDNSLinkUrl
177
+ }
178
+ browser . tabs . update . flush ( )
179
+ assert . ok ( browser . tabs . update . notCalled )
180
+ modifyRequest . onCompleted ( request )
181
+ assert . ok ( browser . tabs . update . withArgs ( { url : fixedDNSLinkUrl } ) . calledOnce )
182
+ browser . tabs . update . flush ( )
183
+ } )
184
+ } )
185
+
162
186
after ( function ( ) {
163
187
delete global . URL
164
188
delete global . browser
0 commit comments